讀我有一個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