适用于iPhone的NSBitmapImageRep(或CGImage的直接像素访问)? [英] NSBitmapImageRep for iPhone (Or direct pixel access for CGImage)?
本文介绍了适用于iPhone的NSBitmapImageRep(或CGImage的直接像素访问)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在UIKit中有一个很好的模拟 NSBitmapImageRep
吗?具体来说,我正在寻找与 setPixel:atX:y:
和 getPixel:atX:y:
。我找到了这个技术说明,它确实让我最开心使用CGImage的方式,但我怎么知道像素的顺序是什么?
Is there a good analog to NSBitmapImageRep
in UIKit? Specifically I'm looking for similar methods to setPixel:atX:y:
and getPixel:atX:y:
. I have found this technote, and it does get me most of the way there using CGImage, but how do I know what order the pixels are in?
推荐答案
CGImageGetBitsPerComponent( image );
CGImageGetBitsPerPixel( image );
CGImageGetBytesPerRow( image );
CGImageGetBitmapInfo( image );
CGColorSpaceGetModel( CGImageGetColorSpace( image ) );
CGColorSpaceGetNumberOfComponents( CGImageGetColorSpace( image ) );
使用上述调用,您可以弄清楚每个像素的布局方式。 x,y的每个像素将从以下开始:
Using the above calls, you can figure out how each pixel is laid out. Each pixel for x,y will start at:
length = CGImageGetBitsPerPixel(image)/CHAR_BIT;
offset = y*CGImageGetBytesPerRow(image) + x*length;
典型的32位ARGB PNG可能是:
A typical 32 bit ARGB PNG might be:
8 = CGImageGetBitsPerComponent( image );
32 = CGImageGetBitsPerPixel( image );
kCGImageAlphaFirst = CGImageGetBitmapInfo( image );
4 = CGColorSpaceGetNumberOfComponents( CGImageGetColorSpace( image ) );
kCGColorSpaceModelRGB = CGColorSpaceGetNumberOfComponents( CGImageGetColorSpace( image ) );
这篇关于适用于iPhone的NSBitmapImageRep(或CGImage的直接像素访问)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文