I have bitmap with a width of 1182, height of 1822. I want to zoom in with the left top coordinate (765,805) aligning with the left top of the imageview. is this possible?
Related
In Android Studio, I created a canvas. Width = 300dp, Height = 300dp.
I draw a line start from left top corner and end to right bottom corner. I traced the x and y coordinates. It is from (0, 0) in left top corner and to (1000+, 1000+) in right bottom corner.
But,
How to set (0,0) in left top corner and (300,300) in right bottom corner?
I have an ImageView in the center of a constraint layout. I want to get its coordinates in the screen for animation. I have referred similar questions, but I always get 0 as the coordinate.
How can I get the coordinates?
What I have tried:
imageView.getTop();
imageView.getX();
imageView.getPivotX();
Rect rect = new Rect();
imageView.getGlobalVisibleRect(rect);
rect.centerX()
Note:
ImageView is placed at the center using constraints and it is of dimension 40dp x 40dp (small image).
I'm going to implement a UI design like the picture in this link (please ignore all text and coordinate in the picture): https://onedrive.live.com/redir?resid=a9a5b8b663e8f93a!25425&authkey=!AClrIvht7LiHDPg&ithint=folder%2cpng
There are 3 circles with the same radius, and 3 circles have overlap where the center of overlap is the screen center. Circle A align parent top and B align parent bottom and left. C is symmetric of B. My question is how can I scale the coordinate of 3 circles and the radius so that on different size of screens it always looks the same? I need to calculate these values on different size of screens:
top margin of circle A
left margin of circle B
bottom margin of circle B
radius of circle
Thank you in advance!
I am trying to create custom components in Android using Surfaceview and canvas drawing. The components are re-sizable and rotatable by touching. Consider creating an image view its Top,Right,Bottom, and Left edges are scalable by touching and dragging the required edge. I am using RectF to keep the bounds of the component, For rotation I am using canvas.rotate(angle, bounds.centerX(),bounds.centerY()) method. The problem is while resizing top edge, the Let , Right and Bottom edges should be fixed, and I cannot able to fix it if the rotation angle is other than 0 degrees. I need a math solution to find out the x,y coordinates of a rotated rectangle with respect to the actual rectangle's bounds.
I can explain it with the help of some images.
The following Figure displays two rectangles whose bounds are also known and displayed in respective colors. Consider the Green Rect as the components initial bounds, ie. rotated by -45 Degrees, Center is (10,10). Now going to re-size the Top edge of the rectangle and displayed in next Figure 2.
From the Figure 2 it is understood that the Y position is reduced to 4 from 6. The rotated Rectangle is also shown in pink color. Remember I am doing resizing while the component is at rotation angle -45 degrees, so while dragging Top Edge rectangle's Left, Right and Bottom positions should not be changed. So the Figure 2's Pink Rectangle should have Left, Right, and Bottom coordinates same as Figure 1's Green Rectangle. Comparison of the obtained and expected rectangle is shown in Figure 3.
In Figure 3 the yellow color rectangle is the Expected/Required out put. The obtained rectangle Pink color is shifted upwards compared to the Green rotated rectangle and that is varying depends on the Angle of rotation.
I have rotation angle = -45 degree
Bounds of Actual (Not re-sized) rectangle.
Bounds of Actual (Not re-sized) rectangle at Rotation = -45 degrees.
Bounds of Re-sized rectangle.
Bounds of Re-sized rectangle at Rotation = -45 degrees.
How do I calculate the Bounds / Center of the Yellow Rectangle. So that I can implement the resizing of my components correctly? Let me know is there is any mathematics that can be applied?
The required points / coordinates are marked as Red color circles in Figure 3.
The key is this: "I cannot able to fix it if the rotation angle is other than 0 degrees."
Let's say your rectangle is rotated 10 degrees.
1) rotate the mouse coordinate around some point on the screen by -10 degrees
2) rotate the center of the rectangle by -10 degrees
... now you reduced the problem to a rectangle that is at 0 degrees. The rectangle moved, yes, the mouse moved, but they are relative to each other as they should be.
3) Now do the the rectangle manipulation. The rectangle center will shift.
4) Rotate the new rectangle center by 10 degrees
This way you do not have to think about it and you are always working in un-rotated coordinates.
Point at [x, y] rotated by angle a will end up at [x*cos(a) - y*sin(a), x*sin(a) + y*cos(a)]
All colors in this answer refer to your figure 3.
If I understood your question correctly, you know how to compute all the details about the pink rectangle as well as the green rectangle. So simply take the difference between one corner of the pink rectangle and the corresponding corner of the green rectangle. Adding that difference (a two-element vector, i.e. x and y difference separately) to the center of the pink rectangle will give you the desired center of the yellow triangle.
If you need to compute the dimensions of the pink rectangle as well, you might want to do so in the unrotated coordinate system. Take your green rectangle together with the coordinates of the point towards which you want to extend the rectangle, and rotate them back by +45°. Then you can extend the height of the rectangle to the value you desire, which will give you the blue rectangle, and from that by rotation the pink rectangle.
How to calculate the coordinates with respect to image after zoom the image?
To zoom the image I followed the url: https://github.com/MikeOrtiz/TouchImageView/blob/master/src/com/example/touch/TouchImageView.java.
if we touch the image at particular point before Zoom then corresponding values are
point:(3,2)
top left corner of image:(0,0)
top left corner of screen:(0,0)
scale factors:(1.25,0.98)
After zoom the image:
if we drag the image until the image top left corner coincides the screen top left corner and touch image exactly at same touch point(before pinch) then
point:(540,220)
top left corner of image:(0,0)
top left corner of screen:(0,0)
scale factors:(4.78,2.67)
if we drag the image until the image top right corner coincides with the screen top right corner and touch image exactly at same touch point(before pinch) then
point:(1080,340)
top left corner of screen:(0,0)
top left corner of image:(-2430,0)
scale factors:(4.78,2.67)
if we drag the image until the image bottom left corner coincides with the screen bottom left corner and touch image exactly at same touch point(before pinch) then
point:(670,80)
top left corner of screen:(0,0)
top left corner of image:(0,-890)
scale factors:(4.78,2.67)
if we drag the image until the image bottom right corner coincides with the screen bottom right corner and touch image exactly at same touch point(before pinch) then
point:(456,274)
top left corner of screen:(0,0)
top left corner of image:(-2430,-890)
scale factors:(4.78,2.67)
if we set the image over the screen [ not to set the any corner]
point:(743,146)
top left corner of screen:(0,0)
top left corner of image:(-1280,-423)
scale factors:(4.78,2.67)
In all the above scenarios I am getting the coordinates in touch event as
x_cord=event.getX();
y_cord=event.getY();
The touch points I am getting are with respect to the screen.
How can I calculate the touch points according to the Image?
Thanks & Regards
mini.
We can calculate by calculating relative point according to the image size
float[] values = new float[9];
matrix.getValues(values);
x_coord = ((e.getX() - values[2])*scaleX )/values[0];
y_coord= ((e.gety() - values[5])*scaleY )/ values[4];
In my case I calculated those points as follows. This will be helpful for someone.
x = (event.getX() / values[Matrix.MSCALE_X] - (values[Matrix.MTRANS_X]/values[Matrix.MSCALE_X]));
y = (event.getY() / values[Matrix.MSCALE_Y] - (values[Matrix.MTRANS_Y]/values[Matrix.MSCALE_Y]));