【发布时间】:2011-12-20 13:11:06
【问题描述】:
我需要从 JPEG 或 PNG 文件中提取原始 RGB 位图数据,包括文件中的所有位,而不是窗口或颜色转换版本。
我是 Cocoa 的新手,但看起来我像这样使用 NSImage 打开图像:
NSString* imageName=[[NSBundle mainBundle] pathForResource:@"/Users/me/Temp/oxberry.jpg" ofType:@"JPG"];
NSImage* tempImage=[[NSImage alloc] initWithContentsOfFile:imageName];
NSBitmapImageRep* imageRep=[[[NSBitmapImageRep alloc] initWithData:[tempImage TIFFRepresentation]] autorelease];
unsigned char* bytes=[imageRep bitmapData];
int bits=[imageRep bitsPerPixel];
然后要获取位图数据,似乎有很多选项:Bitmapimage、CGImage 等。
什么是最简单的方法,如果有代码sn-p,那就太好了。
谢谢!
【问题讨论】: