ImageAsResized
ImageAsResized copied to clipboard
floating point scale and crop bug
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);
~~
great! I'll check and test your patch tomorrow. thanks!
thanks, check this out! https://github.com/yagitoshiro/ImageAsResized/commit/6decf3ff4a82bcf223dcbc010ac26b853082b891
how about this: https://github.com/yagitoshiro/ImageAsResized/commit/3325d3c28b2ed076c60ed94ac3e7e4d8a8e64af6