[英]Maintain drawing path on image with orientation changes in device android
I have issue for maintaining drawing (lines with use of finger) on image while device orientation changes.当设备方向发生变化时,我在图像上保持绘图(使用手指的线条)时遇到问题。
This image shows the drawing on image with finger此图像显示了用手指在图像上的绘图
After change the orientation, the draw line misplaced.改变方向后,画线错位。
I have path object which have this drawing data.我有路径 object 有这个绘图数据。
Please help me to resolve this.请帮我解决这个问题。 Thanks in advance.
提前致谢。
Now, It is obvious that landscape image's height is less than portrait one.现在,很明显横向图像的高度小于纵向图像的高度。 So in this situation image is down scale.
所以在这种情况下,图像是按比例缩小的。 So we need to calculate using some equations to get that value which require to scale down the Path to adjust the position of that Path
所以我们需要使用一些方程式计算得到需要缩小路径以调整该路径的 position 的值
To resolved this, Let's consider the portrait mode's image has H1 height and landscape mode's image has H2 height.为了解决这个问题,让我们考虑纵向模式的图像具有 H1 高度,横向模式的图像具有 H2 高度。
val scale = H2/H1
val matrix = Matrix()
matrix.setScale(scale, scale)
path.transform(matrix)
This way you will update the all the path objects for landscape mode.这样,您将更新横向模式的所有路径对象。
Now when you rotate back to portrait mode, you need to undo scaling by below code.现在,当您旋转回纵向模式时,您需要通过以下代码撤消缩放。
val scale = 1 / (H2/H1)
val matrix = Matrix()
matrix.setScale(scale, scale)
path.transform(matrix)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.