I have an imageview, I want to convert the touch event on the image to its corresponding pixel on the orginal bitmap (even after the image has been gesture scaled or flinged).
How can this be achieved?
Thanks
Related
I'm able to do a scale animation on an imageview but the view crops the image when it's set.
I need to accomplish a scale animation on the image itself because scaling down the view reveals the cropped edges
Is this possible without a frame-by-frame animated drawable?
I don't have any code to share because I'm not even sure where to start
You should scale it's bitmap like this:
Bitmap bitmap = ((BitmapDrawable)imageView.getDrawable()).getBitmap();
//replace first `120` with your target width and second `120` with your target height
imageView.setImageBitmap(Bitmap.createScaledBitmap(bitmap, 120, 120, false));
I tried following some ImageView and BitmapDrawable source code to gain a better understanding of how the two classes operate on BitMaps. Is this generically how the process works?
I have an image which is a JPEG of size 500x500
I have ImageView A which is size 250x250, and ImageView B which is size 500x500.
Both have a BitmapDrawable which contains the JPEG
When its time to draw the Bitmap, A and B will both apply a matrix that will scale the bitmap appropriately to their respective canvas.
The JPEG itself will remain unscaled
I have a ImageView they use a TouchListener with a GestureDetector to handle a SingleTap event, I'm able to get the touch (x,y) position.
Now, I would like to get the pixel coordinates of the touch position. I have play without success with the ImageView matrix..
Getting color from pixcel using bitmap like this:
ImageView imageView =((ImageView)v);
Bitmap bitmap =((BitmapDrawable)imageView.getDrawable()).getBitmap();
int pixel = bitmap.getPixel(x,y);
The situation is as follows:
I have a sampled image shown on screen, from which I can crop a portion of it after it has been rotated.
Once I've got the crop rectangle, I have to map it to the original image, which is unrotated and it's bigger.
Till now the scale factor hasn't been a problem.
This image shows more or less the situation(I know it's not showing the size difference):
Image that helps explains the question
So how can I get the mapped rectangle from Rect P to Rect Q?
In Android using ImageView and Matrix, I want to scale an image to fit in the display area.
Then using pinch, a user can zoom the image.
Using setScaleType(ImageView.ScaleType.FIT_CENTER) I can fit my image in display area. But when I use setScaleType(ImageView.ScaleType.MATRIX), to start zooming the image, the image gets reset to default size.
So my question is how to find a scale matrix which will give same effect as
setScaleType(ImageView.ScaleType.FIT_CENTER).
You need to use mMatrix.setRectToRect and Matrix.ScaleToFit.CENTER with your image coordinates and your view coordinates as the source and destination rectangles.
mMatrix.setRectToRect(new RectF(0,0,mImageView.getMeasuredWidth(),mImageView.getMeasuredHeight()),new RectF(0,0,mImageView.getParent().getMeasuredWidth(),mImageView.getParent().getMeasuredHeight()),Matrix.ScaleToFit.CENTER);