从CGBitmapContextGetData取回图像 [英] Get Image back from CGBitmapContextGetData

查看:122
本文介绍了从CGBitmapContextGetData取回图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个 CGBitmapContext ,并且使用此

So I have a CGBitmapContext and I get the pixel at a touchlocation using this

unsigned char* data = CGBitmapContextGetData (offscreenBuffer);

if (data != NULL) {
    offset = 4*((self.bounds.size.width*round(coord.y))+round(coord.x));
    int alpha =  data[offset];
    int red = data[offset+1];
    int green = data[offset+2];
    int blue = data[offset+3];

} 

然后我像下面那样更改像素颜色。

And then I change the pixel colour like below.

data[offset]=255;
data[offset+1]=255;
data[offset+2]=0;
data[offset+3]=0;

我的问题是如何从修改后的像素取回CGImage,以便我可以更新 CGBitmapContext

My question is how do a get a CGImage back from the modified pixels so that I can update my CGBitmapContext?

任何帮助将不胜感激,谢谢!

Any help will be appreciated, Thanks!

推荐答案

使用 CGBitmapContextCreateImage()从上下文中生成新的 CGImage 修改数据之后。

Use CGBitmapContextCreateImage() to generate a new CGImage from your context after modifying the data.

您对 CGBitmapContextGetData()返回的数据进行的更改应该修改上下文本身。那是可写的指针,而不是副本。

Changes you make to the data returned by CGBitmapContextGetData() should modify the context itself. That's a writable pointer, not a copy.

这篇关于从CGBitmapContextGetData取回图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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