i am working on image ,upload original image in this original image resize the small image this image saved in to database
original image --> resize it (small image )--> small image saved in to database
please forward solution
thanks
To do this you'll want to play around with the Bitmap class.
It has several functions to create new bitmaps form previous ones
Bitmap bmp2 = Bitmap.createScaledBitmap(bmp, width, height, true);
a full list can be found in the documentation :
http://developer.android.com/reference/android/graphics/Bitmap.html
Regarding the save to a database I've never done but it would depend on your server.
Related
What im trying to do is to save an edited bitmap that is composed by 2 bitmaps overlayed. My application allows the user to draw on top of a picture and save it.
My problem is: when i save the result image, it gets smaller, even setting the quality to 100. So, if the user saves and edit the image multiple times, the image will get smaller and smaller.
I save the bitmap with this:
result.compress(Bitmap.CompressFormat.JPEG, 100, fos);
I debugged the code, and at this point the width and height are fine, but after saving, the image shrinks.
I've researched for questions about this, but the ones i've found had no answers that could help me.
What i need is a way to save a bitmap without shrinking it, but i need it to be in image format, like JPG, PNG, etc.
Thanks in advance.
I guess is not at the time when you are saving the image, the issue is when you are editing the image (creating layers). Check that mechanism, maybe you are setting the image size there.
My application uses a SurfaceView to show an image to the user, and have them manipulate stickers on top of the image that has been taken. To reduce memory usage, I have scaled all of these bitmaps to fit within the screen. Now I want to save the image that the user just put all of the stickers on, and I would like to save it with the resolution of the original image. How would a go about doing this without loading the full-size images into memory and risking an OutOfMemoryError? I do not know where to start with this, it seems like an impossible task with the given tools.
In case if you want to save the bitmap without downsizing it. There are two options.
Use largeHeap=true in your Application tag (Manifest).
If you can afford a bit of loss in quality! Compress the bitmap using.
Sample Code
ByteArrayOutputStream out = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 70, out);
Bitmap decoded = BitmapFactory.decodeStream(new ByteArrayInputStream(out.toByteArray()));
Below is the link to the documentation of compress method of Bitmap class.
http://developer.android.com/reference/android/graphics/Bitmap.html#compress(android.graphics.Bitmap.CompressFormat, int, java.io.OutputStream)
I would do the following: You have to decouple the editing and the composition. In editing you save what the user wants in some POJOs ( e.g. sticker number A at position X,Y with rotation R )
Then in the composition-step you work with the Hi-Res images - but only one by one to save memory.
In the worst case you have to work with tiles if you still hit memory constraints.
It seems like there are a few different ways to get a bitmap from the storage on a phone.
I'm reading the data from all the images by using a MediaStore query and I save both the path and the imageId in memory. Then later if I want to upload a small thumbnail of the image I can either:
1) query the mediastore for a micro/mini kind of thumbnail based on the image id, then create a scaled bitmap from that to fit my exact needs (if the micro/mini is not the correct size)
Bitmap bm = MediaStore.Images.Thumbnails.getThumbnail(context.getContentResolver(), imageId, MediaStore.Images.Thumbnails.MINI_KIND, null);
Bitmap.createScaledBitmap(bm, (int)newWidth, (int)newHeight, true);
or
2) fetch the bitmap from the file location and then create a scaled bitmap from that
Bitmap bitmap = BitmapFactory.decodeFile(url);
Bitmap.createScaledBitmap(bitmap, (int)newWidth, (int)newHeight, true);
I was originally doing #1 because I figured the thumbnail generation would be quick from the mediastore which would make the createScaledBitmap process finish quicker rather than creating a scaled bitmap from the fullsize image. Is there a best way or is this difference completely negligible?
I'm not an expert, but I would think that the difference between the two would be negligible, considering that either way you're creating a scaled image. It would seem the only difference would be the time it would take to scale from thumbnail versus scale from bitmap, and either way I think you're talking about nanoseconds.
Honestly, it would seem that you would want to use #1 simply for memory use, rather than loading from full size image and then down sampling, you're loading it from the thumbnail and sizing up if necessary.
I don't want to display the bitmap on the screen. Just trying to create a max square image out of the original image from sdcard and then uploading to server. Is there a way to crop an image without loading the image into memory? or load the image in chunks and then save to file?
I don't know if I understand well the question but this could help:
http://developer.android.com/reference/android/graphics/BitmapRegionDecoder.html
BitmapRegionDecoder can be used to decode a rectangle region from an image. BitmapRegionDecoder is particularly useful when an original image is large and you only need parts of the image.
Hope to help :)
I have a listview that has a photograph from the gallery for each entry but it was blowing up and running out of memory so I resized the image
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inSampleSize = 8;
Bitmap yourSelectedImage = BitmapFactory.decodeFile(photo,opts);
imgView.setImageBitmap(yourSelectedImage);
The problem I have is that each image in the list has to be resized before it is displaying the view.
Is there a way to link to the thumbnail view instead of the full size image so that I don't have to resize them or is there a way to load each picture as it is sized instead of having to wait for them all.
This basically sounds like exactly the sort of thing you want from droid-fu's remote image handling, only simpler (the "remote loading" part is really just scaling an image loaded from the Gallery instead of downloading one from the Web). You should be able to use very similar code. Alternatively, this is pretty close to this SO question about lazy-loading images.