After you searched a lot, I found a โtemporaryโ solution in the same Community, and also thanks for the code from โweakwireโ provided in the same post.
Getting coordinates and width / height from matrix
The idea is simple, all I have is to remove the screen background from the scaled image by cropping. The code is a bit long, but it worked for me.
First get the size of the original bitmap
float imgWidth = imgBitmap.getWidth() float imgHeight = imgBitmap.getHeight()
Get the matrix (the zoom function used in my application uses the "trick" values) the matrices used to scale the image and get the scaledWidth and scaledHeight of the original image.
float[] values = new float[9]; matrix.getValues(values); float globalX = values[2]; float globalY = values[5]; float scaledWidth = values[0]*imgWidth; float scaledHeight = values[4]*imgHeight;
Finally, grab the view and crop the background In my case ("finalView" is the usual name of the view where scaling takes place)
setDrawingCacheEnabled(false); destroyDrawingCache(); finalView.setDrawingCacheEnabled(true); Bitmap bm = Bitmap.createBitmap(finalView.getDrawingCache()); finalView.setDrawingCacheEnabled(false); //Final Image Width & Height int finalWidth = Math.min((int)width,(int)finalView.getWidth()); int finalHeight = Math.min((int)height,(int)finalView.getHeight());
// crop to get a scaled image
Bitmap finalBitmap = Bitmap.createBitmap(bm, (int)globalX, (int)globalY, finalWidth ,finalHeight);
Although this is a workaround, it works for me. If there is an alternative solution, send it.
source share