开发者

NSBitmapImageRep for iPhone (Or direct pixel access for CGImage)?

开发者 https://www.devze.com 2023-01-05 07:04 出处:网络
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 wa

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 wha开发者_Python百科t order the pixels are in?


CGImageGetBitsPerComponent( image );
CGImageGetBitsPerPixel( image );
CGImageGetBytesPerRow( image );
CGImageGetBitmapInfo( image );
CGColorSpaceGetModel( CGImageGetColorSpace( image ) );
CGColorSpaceGetNumberOfComponents( CGImageGetColorSpace( image ) );

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;

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 ) );
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号