有没有比 Quartz 2D 更好/更快的方法来处理相机图像?

发布于 2024-10-27 11:57:33 字数 711 浏览 0 评论 0原文

我目前正在开发一个 iPhone 应用程序,它允许用户使用相机拍照,然后使用 Quartz 2D 对其进行处理。

使用 Quartz 2D,我转换上下文以使图片以正确的方向显示(缩放和平移,因为它是镜像的),然后我使用混合模式堆叠一堆图层来处理图片。

初始(和最终结果)图片为 3mp 或 5mp,具体取决于设备,并且绘制后会占用大量内存。 提醒:它不是内存中的 jpeg,而是位图数据。

我的图层与初始图片的大小相同,因此每次我在图片顶部绘制新图层时,我都需要当前图片状态内存 (A) + 混合层内存空间 (B) + 内存中用于写入结果的空间 (C)。

当我得到结果时,我放弃“A”和“B”,将“C”带到下一阶段的处理,在那里它成为新的“A”...

我需要像这样的4次传递才能获得最终图片。

考虑到这些图片的分辨率,我的内存使用量可能会很高。 我可以看到 14Mo-15Mo,大多数时候我只收到 1 级警告,但 2 级警告有时会向我挥手并杀死我的应用程序。

  • 关于一般流程,我是否以正确的方式这样做?
  • 有没有办法加快处理速度?
  • 为什么哦为什么内存警告随机产生?
  • 为什么第二个图片过程比第一个图片过程长,如您在这张图片中看到的:

instruments Screenshot

I'm currently working on an iphone app that lets the user take a picture with the camera and then process it using Quartz 2D.

With Quartz 2D I transform the context to make the picture appear with the right orientation (scale and translate because it's mirrored) and then I stack a bunch of layers whith blending modes to process the picture.

The initial (and the final result) picture is 3mp or 5mp depending on device and it takes a great amount of memory once drawn. Reminder : it's not a jpeg in memory, it's bitmap data.

My layers are the same size as the initial picture so every time i draw a new layer on top of my picture i need the current picture state in memory (A) + the layer to blend memory space (B) + the space in memory to write the result (C).

When i get the result i ditch "A" and "B", takes "C" to the next stage of processing where it become the new "A"...

I need 4 pass like this to obtain the finale picture.

Giving the resolution of these pictures my memory usage can climb high.
I can see a peek at 14Mo-15Mo and most of the time i only get level 1 warnings but level 2s sometimes wave at me and kill my app.

  • Am i doing this the right way regarding general process ?
  • Is there a way to speed up the processing ?
  • Why oh why memory warnings spawn randomly ?
  • Why the second picture process is longer than the first as you can see in this pic:

instruments screenshot

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

放血 2024-11-03 11:57:33

因为持续时间看起来大约是原来的两倍;我想说它的处理量是原来的两倍。拍摄第三张照片需要三倍的时间吗?

如果是这样,这似乎表明它正在处理之前拍摄的所有照片/图层。当然,这是您代码中某处的错误。

Because the duration looks to be about twice as long; I'd say it was doing twice as much processing. Does the third photo taken take three times as long?

If so, that would seem to indicate it's processing all previous photos / layers taken. Which - of course - is a bug in your code somewhere.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文