iPhone - 获取一个指针背后CGDataProvider数据? [英] iPhone - Get a pointer to the data behind CGDataProvider?

查看:1144
本文介绍了iPhone - 获取一个指针背后CGDataProvider数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图采取CGImage和它的数据复制到供以后处理的缓冲区。下面的code是什么,我有这么远,但有一件事我不喜欢它 - 它的两次复制图像数据。一旦 CGDataProviderCopyData(),一次用于:的getBytes:上imgData长度电话。我一直没能找到一种方法将图像数据直接复制到我的缓冲区,并切出的 CGDataProviderCopyData()一步,但必须有一个方式.. .ANY指针? (双关语... FTW)


的NSData * imgData =(NSData的*)(CGDataProviderCopyData(CGImageGetDataProvider(myCGImageRef)));CGImageRelease(myCGImageRef);//我得pviously定义指针到一个可用缓冲器$ P $称为mybuff
[imgData的getBytes:长度mybuff:imgData长度]];


解决方案

看到这个答案:
<一href=\"http://stackoverflow.com/questions/2744639/cocoa-does-cgdataprovidercopydata-actually-copy-the-bytes-or-just-the-point\">http://stackoverflow.com/questions/2744639/cocoa-does-cgdataprovidercopydata-actually-copy-the-bytes-or-just-the-point

看起来直接进入后面的CGDataProvider缓冲区仅限于私人的API。

I'm trying to take a CGImage and copy its data into a buffer for later processing. The code below is what I have so far, but there's one thing I don't like about it - it's copying the image data twice. Once for CGDataProviderCopyData() and once for the :getBytes:length call on imgData. I haven't been able to find a way to copy the image data directly into my buffer and cut out the CGDataProviderCopyData() step, but there has to be a way...any pointers? (...pun ftw)

NSData *imgData = (NSData *)(CGDataProviderCopyData(CGImageGetDataProvider(myCGImageRef)));

CGImageRelease(myCGImageRef);

// i've got a previously-defined pointer to an available buffer called "mybuff"
[imgData getBytes:mybuff length:[imgData length]];

解决方案

See this answer: http://stackoverflow.com/questions/2744639/cocoa-does-cgdataprovidercopydata-actually-copy-the-bytes-or-just-the-point

Looks like direct access to the buffer behind a CGDataProvider is restricted to private APIs.

这篇关于iPhone - 获取一个指针背后CGDataProvider数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆