我将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在相同的上下文中绘制一些文本。
你知道怎么回事吗?