ImageAsResized icon indicating copy to clipboard operation
ImageAsResized copied to clipboard

floating point scale and crop bug

Open p0las opened this issue 11 years ago • 3 comments

Hi, I think I now why you code sometimes doesn't work. BitmapFactory.decodeByteArray returns smaller image if you pass inSampleSize >1. however later you still use original dimensions to crop the image. You need to recalculate x,y,w,h that you use for cropping (Bitmap.createBitmap) for the new smaller resolution. The matrix in Bitmap.createBitmap happens after the crop and can scale image further. the scale passed to the matrix can be float and works without any issues. But that scale has nothing to do with the crop dimensions you pass to the function.

thank you for your module. I was able to learn from it and write my custom one that does just one thing - centre crop and scale to desired resolution (to create square thumbnails in one operation). Without your code I wouldn't have a clue where to start.

Bitmap image_base = BitmapFactory.decodeByteArray(image_data, 0, image_data.length, opts);
        Matrix matrix = getScaleMatrix(opts.outWidth, opts.outHeight, image_base.getWidth(), image_base.getHeight());
        if(rotate > 0){
          matrix.postRotate(rotate);
        }

        //width, height etc passed here are form original image not scaled down image_base.
        return returnBlob(opts, image_base, matrix, width, height, x, y);

~~

p0las avatar Jul 02 '13 14:07 p0las

great! I'll check and test your patch tomorrow. thanks!

yagitoshiro avatar Jul 04 '13 15:07 yagitoshiro

thanks, check this out! https://github.com/yagitoshiro/ImageAsResized/commit/6decf3ff4a82bcf223dcbc010ac26b853082b891

yagitoshiro avatar Jul 06 '13 16:07 yagitoshiro

how about this: https://github.com/yagitoshiro/ImageAsResized/commit/3325d3c28b2ed076c60ed94ac3e7e4d8a8e64af6

yagitoshiro avatar Aug 07 '13 21:08 yagitoshiro