如何从 UIImage NSLog 像素 RGB?
我只想:
1) 复制像素数据。
2) 迭代并修改每个像素(仅向我展示如何将 ARGB 值 NSLog 为 255)
3) 从新的像素数据创建 UIImage
如果有人能告诉我如何将像素的 RGBA 值 NSLog 为 255,我可以弄清楚具体的细节。我该如何修改下面的代码可以做到这一点?请具体说明!
-(UIImage*)modifyPixels:(UIImage*)originalImage
{
NSData* pixelData = (NSData*)CGDataProviderCopyData(CGImageGetDataProvider(originalImage.CGImage));
uint myLength = [pixelData length];
for(int i = 0; i < myLength; i += 4) {
//CHANGE PIXELS HERE
/*
Sidenote: Just show me how to NSLog them
*/
//Example:
//NSLog(@"Alpha 255-Value is: %u", data[i]);
//NSLog(@"Red 255-Value is: %u", data[i+1]);
//NSLog(@"Green 255-Value is: %u", data[i+2]);
//NSLog(@"Blue 255-Value is: %u", data[i+3]);
}
//CREATE NEW UIIMAGE (newImage) HERE
return newImage;
}
I just want to:
1) Copy the pixel data.
2) Iterate and Modify each pixel (just show me how to NSLog the ARGB values as 255)
3) Create a UIImage from the new pixel data
I can figure out the the gory details if someone can just tell me how to NSLog the RGBA values of a pixel as 255. How do I modify the following code to do this? Be Specific Please!
-(UIImage*)modifyPixels:(UIImage*)originalImage
{
NSData* pixelData = (NSData*)CGDataProviderCopyData(CGImageGetDataProvider(originalImage.CGImage));
uint myLength = [pixelData length];
for(int i = 0; i < myLength; i += 4) {
//CHANGE PIXELS HERE
/*
Sidenote: Just show me how to NSLog them
*/
//Example:
//NSLog(@"Alpha 255-Value is: %u", data[i]);
//NSLog(@"Red 255-Value is: %u", data[i+1]);
//NSLog(@"Green 255-Value is: %u", data[i+2]);
//NSLog(@"Blue 255-Value is: %u", data[i+3]);
}
//CREATE NEW UIIMAGE (newImage) HERE
return newImage;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这个方向对你有用吗?我会得到这样的像素数据:
Did this direction work for you? I'd get pixel data like this:
如果您想实际查看图像,可以使用 Florent Pillet 的 NSLogger:
https://github.com/fpillet/NSLogger
这个想法是在桌面上启动 NSLogger 客户端,然后在您的应用程序中将其放在顶部:
在您的
modifyPixels
方法中,您可以执行以下操作:在桌面上启动客户端,然后在 iPhone 上运行该应用程序,然后您将会看到真实的图像出现在客户端中。对于调试图像问题非常方便,例如翻转、旋转、颜色、alpha 等。
If you'd like to actually see the image, you can use Florent Pillet's NSLogger:
https://github.com/fpillet/NSLogger
The idea is you start the NSLogger client on your desktop, and then in your app you put this up towards the top:
And in your
modifyPixels
method you can do something like this:Start the client on your desktop, and then run the app on your iphone, and you'll see real images appear in the client. VERY handy for debugging image problems such as flipping, rotating, colors, alpha, etc.