我將NSBitmapImageRep保存爲BMP文件(Snow Leopard)。當我在macos上打開它時似乎沒問題。但它會在我的多媒體設備上發生錯誤(它可以顯示來自Internet的任何BMP文件)。我無法弄清楚什麼是錯的,但是當我看到裏面的文件(與MacOS的清涼hexfiend應用程序),錯誤的兩兩件事:將NSBitmapImageRep另存爲NSBMPFileType文件。錯誤的BMP標題和位圖內容
- 頭具有的biHeight參數錯誤值:4294966216(十六進制= C8FBFFFF) 頭部具有正確的雙寬度參數:1920
- 位圖內容中的第一個像素(位於BMP格式的54個字節標頭之後)對應於原始圖像的左上角。在原始的BMP文件中,如BMP格式所指定的,它應該是第一個左下角的像素。
爲了解釋我的應用程序的完整工作流程,我有一個NSImageView,我可以拖動BMP圖像。該視圖綁定到NSImage。 拖動後&我有一個行動來保存這個圖像(與一些文字在它上面)到一個BMP文件。
下面是保存新BMP文件代碼:
CGColorSpaceRefcolorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
CGContextRefcontext = CGBitmapContextCreate(NULL, (int)1920, (int)1080, 8, 4*(int)1920, colorSpace, kCGImageAlphaNoneSkipLast);
[duneScreenViewdrawBackgroundWithDuneFolder:self inContext:context inRect:NSMakeRect(0,0,1920,1080) needScale:NO];
if(folderType==DXFolderTypeMovie) {
[duneScreenViewdrawSynopsisContentWithDuneFolder:self inContext:context inRect:NSMakeRect(0,0,1920,1080) withScale:1.0];
}
CGImageRef backgroundImageRef = CGBitmapContextCreateImage(context);
NSBitmapImageRep*bitmapBackgroundImageRef = [[NSBitmapImageRepalloc] initWithCGImage:backgroundImageRef];
NSData*data = [destinationBitmap representationUsingType:NSBMPFileType properties:nil];
[data writeToFile:[NSStringstringWithFormat:@"%@/%@", folderPath,backgroundPath] atomically: YES];
的duneScreenViewdrawSynopsisContentWithDuneFolder方法使用CGContextDrawImage繪製圖像。 duneScreenViewdrawSynopsis方法使用CoreText在相同的上下文中繪製一些文本。
你知道怎麼回事嗎?