This is my code
//originBitmap is bitmap in imageview
setMatrix(originBitmap.getWidth()/2,originBitmap.getHeight()/2);
void setMatrix(float x,float y){
matrix.setTranslate(matrixX,matrixY);
matrix.preRotate(matrixR,x,y);
matrix.preScale(matrixS,matrixS,x,y);
imageView.setImageMatrix(matrix);
}
My code is work currectly in this situation. pic1(blue=imageview, red=bitmap image)
But when this situation, pic2 image rotate around it's center, so users see strange image what moves around strange position.
How can I rotate image around imageview's center position?
Related
I know the x and y coordinates in an bitmap and want to draw a rectangle there. I think this picture illustrates what I want.
Lets say I want to draw a green rectangle over the red one. I know the coordinates of the top left corner and the coordinates of the bottom left corner. Usually it should not be a problem. But I display the bitmap in an Imageview. I use this code to map the coordinates form the bitmap to the coordinates in the canvas of the imageview. For image_view_width and image_view_height I use the getHeight and getWidth form inside of the Imageview.
This solution works on my real device but on the emulator it shows the rectangle on the wrong position. Can someone help me and tell me what is wrong?
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?
I'm using the matrix.rotate(deg, fx,fy) method to rotate an image.
The image has an alpha channel and only has something visual in the right-hand corner. I want to rotate the canvas, create the new image with that matrix and have the visual part be the only part that is rotating.
At the moment the image rotates but doesn't rotate around the desired axis. It always rotates around the original width of the object.
Here is the code I use:
Matrix matrix = new Matrix();
matrix.setRotate(rotation, xPivot, yPivot);
Bitmap pic1a = Bitmap.createBitmap(pic1, 0, 0, pic1.getWidth(), pic1.getHeight(), matrix, true);
This rotates the image correctly but only seems to rotate within the same location of the original canvas.
What I want is for the point that the image rotates around (xPivot, yPivot) becoming the centre location on the display.
I have an activity which consists of just an ImageView. The drawable contained in the ImageView is a Bitmap that was captured from the camera. The image is automatically scaled (maintaining the Bitmap's aspect ratio) so that the scaled width matches the width of the ImageView, and the image is centered on the screen vertically.
I need to figure out the coordinates of the top-left pixel of the actual drawable (not of the ImageView itself), but the ImageView class doesn't seem to give me a way of doing that.
I feel like I could potentially calculate it based on the dimensions of the original bitmap and the dimensions of the ImageView, but that would involve a lot of math that should be unnecessary, and would be prone to floating point errors.
Does anyone know of a way to find the coordinates of the top-left pixel of the Drawable relative to the ImageView?
Thanks.
Looking at the ImageView source code, it translates a Matrix halfway the vertical size (i.e., center it vertically), so you could retrieve it with the ImageView getImageMatrix() method and check the vertical translation by Matrix#getValues(float[]). If I read it right, it will be the sixth value.
I can't test it right now, but it would be something like:
Matrix matrix = iv.getImageMatrix ();
float[] values = new float[];
matrix.getValues(values);
float startY = values[5];