简体   繁体   English

在设备 android 中保持方向更改的图像上的绘图路径

[英]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.

相关问题 方向更改扭曲了Android设备中的视图 - Orientation Changes distorted the View in Android device Android-ImageView方向会因设备而异 - Android - ImageView Orientation changes depending on device Android gridview会在更改方向时保持状态,但需要更新视图 - Android gridview maintain the state when changes orientation but need to update views JqueryMobile - 设备方向更改 - JqueryMobile - Device Orientation changes Android图像旋转会因设备而异 - Android image rotation changes from device to device 我的android活动如何知道设备何时改变方向 - How does my android activity knows when the device changes in orientation 如何在android中设备方向更改后保持listview项的突出显示 - How to keep highlight of listview item after device orientation changes in android 为什么此代码不显示Android设备方向更改? - Why won't this code show Android device orientation changes? 当Android设备更改方向时,如何处理Admob adView? - What to do to Admob adView when Android device changes orientation? 从android中的服务器下载图像后图像方向发生变化 - Image orientation changes after downloaded image from server in android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM