读我有一个NSBitmapImageRep,我创建方式如下:NSBitmapImageRep产生BMP不能在Windows
+ (NSBitmapImageRep *)bitmapRepOfImage:(NSURL *)imageURL {
CIImage *anImage = [CIImage imageWithContentsOfURL:imageURL];
CGRect outputExtent = [anImage extent];
NSBitmapImageRep *theBitMapToBeSaved = [[NSBitmapImageRep alloc]
initWithBitmapDataPlanes:NULL pixelsWide:outputExtent.size.width
pixelsHigh:outputExtent.size.height bitsPerSample:8 samplesPerPixel:4
hasAlpha:YES isPlanar:NO colorSpaceName:NSDeviceRGBColorSpace
bytesPerRow:0 bitsPerPixel:0];
NSGraphicsContext *nsContext = [NSGraphicsContext graphicsContextWithBitmapImageRep:theBitMapToBeSaved];
[NSGraphicsContext saveGraphicsState];
[NSGraphicsContext setCurrentContext: nsContext];
CGPoint p = CGPointMake(0.0, 0.0);
[[nsContext CIContext] drawImage:anImage atPoint:p fromRect:outputExtent];
[NSGraphicsContext restoreGraphicsState];
return [[theBitMapToBeSaved retain] autorelease];
}
而且被保存为BMP这样:
NSBitmapImageRep *original = [imageTools bitmapRepOfImage:fileURL];
NSData *converted = [original representationUsingType:NSBMPFileType properties:nil];
[converted writeToFile:filePath atomically:YES];
的东西在这里是BMP文件可以在Mac OSX下正确读取和操作,但在Windows下,它只是无法加载,就像在此屏幕截图中一样:
screenshot http://dl.dropbox.com/u/1661304/Grab/74a6dadb770654213cdd9290f0131880.png
如果使用MS Paint打开文件(是的,MS Paint可以打开它),然后重新保存,但它将起作用。
希望能在这里找到一只手。 :)
在此先感谢。
您好,首先感谢您的帮助。你是对的,保留] autorelease]根本没有意义。你的代码似乎比我以前的代码好多了。唯一的问题是,BMP的内置文件查看器仍然无法打开,与上面相同的错误。 (你可能还想修复你的第二个方法,以防有人想使用它。你不能调用self,因为对象没有被分配,fileURL应该是imageURL)。 – MegaEduX
你*可以*调用self,因为它是调用另一个类方法的类方法。 –
噢,我想我一直在学习。知道怎么了BMP问题? – MegaEduX