NSBitmapImageRep数据格式为应用程序图标图像?

时间:2010-04-01 20:42:16

标签: cocoa macos

我有一个char *数组,在RGBA中,然后移到ARGB

底线是设置的应用程序图像看起来完全搞砸了,我无法理解为什么?

    //create a bitmap representation of the image data.
   //The data is expected to be unsigned char**
   NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc]
       initWithBitmapDataPlanes : (unsigned char**) &dest
       pixelsWide:width pixelsHigh:height
       bitsPerSample:8
       samplesPerPixel:4
       hasAlpha:YES
       isPlanar:NO
       colorSpaceName:NSDeviceRGBColorSpace
       bitmapFormat: NSAlphaFirstBitmapFormat
       bytesPerRow: bytesPerRow
       bitsPerPixel:32 ];

   //allocate the image
   NSImage *image = [[NSImage alloc] initWithSize:NSMakeSize(width, height)];
   [image addRepresentation:bitmap];


   if( image == NULL) {
       printf("image is null\n");
       fflush(stdout);
   }

   //set the icon image of the application
   [NSApp setApplicationIconImage :image];

   //tell the image to autorelease when done
   [image autorelease];

这些价​​值观中哪些不对?图像看起来非常多彩,像素化,透明的部分/线条也是如此。

编辑:将每行的字节数更改为宽度* 4(扫描线)后,这是我得到的图像。 ![替代文字] [1]

原始图像只是一个橙色方块。

EDIT2:更新的图像和一些参数。

谢谢!

alt text http://www.freeimagehosting.net/uploads/3793520d98.png

1 个答案:

答案 0 :(得分:1)

如果你还为数据传递NULL(并让rep自己分配),那么为bytesPerRow指定0是很有用的。如果传递零,则要求系统使用“最佳”bytesPerRow,这在架构和操作系统版本之间不稳定。它不是宽度* bitsPerPixel,它是用于对齐的。

这至少是错误的。

相关问题