gpt4 book ai didi

ios - 如何将 Color32[] 图像从 WebCamTexture 转换为 iOS 中的 UIImage?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:42:04 25 4
gpt4 key购买 nike

有谁知道如何有效地做到这一点?我正在使用 EncodeToPNG() 函数,但性能真的很慢。

我正在尝试使用 WebCamTexture 捕获 Ipad 相机图像并将其发送到 Objective C 端进行一些处理。我注意到可以发送纹理的 native 地址,但我应该如何在 ObjC 端处理它?有人对此有任何提示吗?

谢谢!

最佳答案

正如您所说的 EncodeToPNG 的性能太慢,您需要做的是在相机源从 iOS ( objc ) 发送到 Unity 的 WebCamTexture 之前挂入代码。

我们使用了类似的技术和一个名为 CameraCaptureKit (https://www.assetstore.unity3d.com/en/#!/content/56673) 的插件来卡住发送到 Unity 的图像,同时等待 Flash 和防抖被打开。

在Unity生成的xcode工程中打开CameraCapture.mm,找到函数。

- (void)captureOutput:(AVCaptureOutput*)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection*)connection

然后可以通过修改这段代码来修改发送到Unity的WebCamTexture的图片。 UnityDidCaptureVideoFrame 是您要插入的代码。

intptr_t tex = (intptr_t)CMVideoSampling_SampleBuffer(&self->_cmVideoSampling, sampleBuffer, &self->_width, &self->_height);
UnityDidCaptureVideoFrame(tex, self->_userData);

干杯

关于ios - 如何将 Color32[] 图像从 WebCamTexture 转换为 iOS 中的 UIImage?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17283733/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com