简体   繁体   English

如何在iPhone上调整UIImage的RGB像素数据?

[英]How can I adjust the RGB pixel data of a UIImage on the iPhone?

I want to be able to take a UIImage instance, modify some of its pixel data, and get back a new UIImage instance with that pixel data. 我希望能够获取一个UIImage实例,修改其某些像素数据,并使用该像素数据重新获得一个新的UIImage实例。 I've made some progress with this, but when I try to change the array returned by CGBitmapContextGetData, the end result is always an overlay of vertical blue lines over the image. 我已经取得了一些进展,但是当我尝试更改CGBitmapContextGetData返回的数组时,最终结果始终是图像上垂直蓝线的叠加。 I want to be able to change the colors and alpha values of pixels within the image. 我希望能够更改图像中像素的颜色和alpha值。

Can someone provide an end-to-end example of how to do this, starting with a UIImage and ending with a new UIImage with modified pixels? 有人可以提供一个如何做到这一点的端到端示例,以UIImage开头并以像素已修改的新UIImage结尾吗?

This might answer your question: How to get the RGB values for a pixel on an image on the iphone 这可能会回答您的问题: 如何在iPhone上获取图像上像素的RGB值

I guess you'd follow those instructions to get a copy of the data, modify it, and then create a new CGDataProvider (CGDataProviderCreateWithCFData), use that to create a new CGImage (CGImageCreate) and then create a new UIImage from that. 我想您会按照这些说明来获取数据的副本,对其进行修改,然后创建一个新的CGDataProvider(CGDataProviderCreateWithCFData),使用它来创建一个新的CGImage(CGImageCreate),然后从中创建一个新的UIImage。

I haven't actually tried this (no access to a Mac at the moment), though. 我实际上还没有尝试过(目前无法访问Mac)。

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

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