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.
Related
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.
Well, i am trying to reduce the size(bits) of an image, which will be taken using camera. I have already reduced it by reducing its height and width. But a lot of questions came infront.
IIsnt it possible that within same height & width- an image can contain more/less resolutions. I mean- cant resolution vary within images which have same height & width?
Is there other properties of image/color, which we can change and make the total image size(bits) become less?
Any other solutions? :-)
Use Bitmap to compress your image.
This can be done by calling;
Bitmap bm=//intialize your image here
FileOutputStream fos=//intialize your OutputStream here
bm.compress(Bitmap.JPEG, 50, fos)// the Number stands for the quality of the image, the format of the image can be changed if you want to
For further information see the Android API here.
Is it possible to scale image without loosing its quality?I have seen posts that say to use Ninepatch images but how can we download an image and convert it to ninepatch image so that i can show it in ImageView.
Is there any other way so that my images with smaller size can be scaled like in whats app
Everytime you scale an image it's losing quality, the only thing you can do to keep the quality is keeping a copy of the original image (which doesn't make much sense since you can just load it again from resources).
If you mean the problem was that android was scaling your images (and changing the quality) you can put images on a folder named "raw" inside res.
Ninepatch images can be made manually by you, you just paint an image that has two extra pixels on width and two on height, and when you save it , name it something.9.png
if you want to know how to draw them correctly follow this: http://developer.android.com/tools/help/draw9patch.html
I'm creating somekind of 2D image editor in Android and I have the big problem of big files don't fit in memory.
I need to zoom in/out the image put some shapes and then save it.
My question is:
How can I load the image and save it without getting out of memory?
I've been reading about bitmapregiondecode and the sample technic but there's must be another solution. How can I save the image if I always use regiondecode?
The images need good detail quality because it's architectural images... and the lines must be well defined.
I'm new to this, help me please.
Note two things while dealing with images:
tempBitmap = Bitmap.createBitmap(bit);
clone the bitmap which you are using for zoom and other operations but wont use the original because it looses its clarity when you save;
when done with bitmap give
bit.recycle();
to release the memory space
I am using the Camera activity to capture the JPEG image. After image is saved and the controll is returned back to my application activity I would like to to determine the captured JPEG image dimensions without loading the whole image into memory via Bitmap object - can it be easily done somehow?
Is there any class, which reads the JPEG header and give me such information? I would like to avoid OOM conditions - but might be it is not a problem to load the whole image into memory - is it?
After knowing the dimensions I would like to use BitmapFactory to scale the image.
Thanks a lot
Kind Regards,
STeN
Perhaps a work-around (see 2nd approach) by setting the quality?
bmp.compress(CompressFormat.JPEG, 75,
pfos);
You would have to do a trial run to see what size the quality gets you though...
*The first approach creates a log file to get the width and height but not sure if you wanted the extra step of looking at a log file.
You can use the ExifInterface class to read the image width and height.