简体   繁体   English

Android和iOS平台或相同平台之间的屏幕镜像

[英]Screen mirroring among Android and iOS platform or same platforms

I am looking forward to build an app which will support the screen mirroring concept. 我期待构建一个支持屏幕镜像概念的应用程序。 how shall I implement it I am just not able to get it I have read multiple docs on Chrome cast reflector 2, I need to build an app in which I can simply share my screen among Android to iPhone or on the same platform also. 我应该如何实现?我只是无法获得它,我已经在Chrome Cast反光镜2上阅读了多个文档,我需要构建一个应用程序,可以在Android,iPhone或同一平台上轻松共享屏幕。 please help any references any advice will be appreciated. 请帮助任何参考,任何建议将不胜感激。

You may consider making a function which returns a UI image of your screen with something along the lines of UIGraphicsBeginImageContextWithOptions(self.view.size, false, 0.5) view.drawHierarchy(in: view.frame, afterScreenUpdates: true) let image = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() with the given quality parameters you set. 您可以考虑创建一个函数,该函数返回屏幕的UI图像,并带有类似UIGraphicsBeginImageContextWithOptions(self.view.size, false, 0.5) view.drawHierarchy(in: view.frame, afterScreenUpdates: true) let image = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext()具有您设置的给定质量参数的UIGraphicsBeginImageContextWithOptions(self.view.size, false, 0.5) view.drawHierarchy(in: view.frame, afterScreenUpdates: true) let image = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() The image context is thread- safe, don't worry. 图像上下文是线程安全的,不用担心。 https://developer.apple.com/documentation/uikit/1623912-uigraphicsbeginimagecontextwitho . https://developer.apple.com/documentation/uikit/1623912-uigraphicsbeginimagecontextwitho I don't know the quality settings you may want, but you can change that. 我不知道您可能想要的质量设置,但是您可以更改它。 Then you could make a function/ class that will send whatever data you have in a serialized buffer. 然后,您可以创建一个函数/类,该函数/类将发送序列化缓冲区中的所有数据。 I'm assuming that since this is for screen mirroring, a type of streaming, you may want to use UDP as your data transport protocol since it doesn't care whether or not some packets are lost because they just keep coming, ie there's no 3- way handshake. 我假设由于这是用于屏幕镜像(一种流式传输),因此您可能希望使用UDP作为数据传输协议,因为它并不关心是否有一些数据包丢失了,因为它们只是不断地传来,即没有3种方式的握手。 You may want to see this forum post Swift: Receive UDP with GCDAsyncUdpSocket for more info on transferring data via UDP. 您可能需要查看此论坛帖子Swift:使用GCDAsyncUdpSocket接收UDP,以获取有关通过UDP传输数据的更多信息。 In short, you'll need to serialize your data(convert it to bytes) to send it in a small format and deserialize it on the other end where you have your socket connected device listening for new data which it converts into an image. 简而言之,您需要对数据进行序列化(将其转换为字节),以便以较小的格式发送数据,并在另一端进行反序列化,在该另一端,与套接字连接的设备将侦听新数据并将其转换为图像。 Finally, you need to ensure that your screen capture function, which returns 1 image, is called several times per second. 最后,您需要确保每秒调用几次返回1张图像的屏幕捕获功能。 Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM