I resize a bitmap using the following code:
FileOutputStream out = new FileOutputStream("/sdcard/mods.png");
Bitmap bmp = Bitmap.createScaledBitmap(pict, (int)(pict.getWidth() / totScale),
(int)(pict.getHeight() / totScale), false);
bmp.compress(Bitmap.CompressFormat.PNG, 90, out);
out.close();
The code for getting the bitmap from the camera that I am using is the following:
mCamera.takePicture(null, null, null, new Camera.PictureCallback() {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
pict = BitmapFactory.decodeByteArray(data, 0, data.length);
}
});
The first picture is what I can see on the phone (in Astro file manager), and also when I draw the bitmap in my application on a canvas. This happens on every device I've tested on (HTC Legend and Galaxy Tab) The second picture is what it looks like on my computer. What is causing the blocks on the device?
Here is what fixed my problem: Instead of
pict = BitmapFactory.decodeByteArray(data, 0, data.length);
I replaced that with
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inPreferredConfig = Bitmap.Config.ARGB_8888;
pict = BitmapFactory.decodeByteArray(data, 0, data.length, opts);
Tap the image you want to adjust. You can adjust the size of an image or rotate it: Resize: Touch and drag the squares along the edges. Rotate: Touch and drag the circle attached to the image.
1) Try changing the filter parameter from "false" to "true" in your call to createScaledBitmap(). I bet that will fix your problem.
You should read this article: http://www.curious-creature.org/2010/12/08/bitmap-quality-banding-and-dithering/
First and second pictures are the same.
P.S.
bmp.compress(Bitmap.CompressFormat.PNG, 90, out);
You cant compress PNG format, only JPEG.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With