如何将点数从一个设备转换到另一个设备

huangapple go评论146阅读模式
英文:

How to convert points from one device to another device

问题

Device 1

Device 1正在向设备2传输视频流。当我在视频容器视图的图层上绘制一条线时,我希望在第二个设备上以与视频相关的相同位置重新绘制该线。透过的红色背景来自包含视频图层的视图。视频图层的contentsGravity设置为.resizeAspectFill。

我已经尝试过将点转换并重新绘制线条,但位置不正确。

var targetCoord = CGPoint()
        
targetCoord.x = originCoord.x / originScreenSize.width * targetScreenSize.width
targetCoord.y = originCoord.y / originScreenSize.height * targetScreenSize.height

如何考虑顶部间隙和侧边间隙(红色区域)的差异?将形状图层添加到缓冲区并发送到另一台设备是不可行的,因为这会很慢,而且需要双向传输绘图。我很难理解这个问题,感谢任何帮助!

英文:

如何将点数从一个设备转换到另一个设备

Device 1

如何将点数从一个设备转换到另一个设备

Device 2

Device 1 is streaming video feed to device 2. When I draw a line on top of the video container view's layer above the video layer, I'd like to redraw the line on the second device on the same spot in relation to the video. Red background that is showing through is from the view that contains the video layer. The video layer's contentsGravity is set to .resizeAspectFill.

I have attempted to convert the points and redraw the line but it is off.

var targetCoord = CGPoint()
        
targetCoord.x = originCoord.x / originScreenSize.width * targetScreenSize.width
targetCoord.y = originCoord.y / originScreenSize.height * targetScreenSize.height

How can I take into accounts the differences in the top gap and the side gap(red area)? Adding the shape layer to the buffer and sending to the other device is not feasible since it's slow and the drawings need to go both ways. I am having a hard time wrapping my head around it and I'd appreciate any help!

答案1

得分: 0

首先,我需要使用 AVMakeRect(aspectRatio:insideRect) 来获取适合视频的矩形,并将包含视频层的视图的框架设置为去掉两个视图上的红色区域。这样,点将完全对应。

对于转换,我有正确的想法,但我使用了错误的宽度和高度值。不要使用屏幕大小,而是使用包含视频层的视图的大小。

var targetCoord = CGPoint()
       
targetCoord.x = originCoord.x / sourceViewSize.width * targetViewSize.width
targetCoord.y = originCoord.y / sourceViewSize.height * targetViewSize.height
英文:

First of all, I needed to get rid of the red area on both views by using AVMakeRect(aspectRatio:insideRect) to get the rect that fits the video and set the frame of the view containing the video layer. This way points will correspond exactly.

I had the right idea for the conversion but I was using the wrong values for the width and height. Instead of using the screen size, use the size of the views containing the video layer.

var targetCoord = CGPoint()
       
targetCoord.x = originCoord.x / sourceViewSize.width * targetViewSize.width
targetCoord.y = originCoord.y / sourceViewSize.height * targetViewSize.height

huangapple
  • 本文由 发表于 2023年8月10日 09:49:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/76872167.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定