gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 18:05:42 26 4
gpt4 key购买 nike

我有一个 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]

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

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

谢谢!

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

最佳答案

如果您还为数据传递 NULL(从而让代表自行分配它),则为 bytesPerRow 指定 0 才有用。如果传递零,则表示您要求系统使用“最佳”bytesPerRow,这在体系结构和操作系统版本之间不稳定。它不是 width*bitsPerPixel,而是为了对齐而进行了填充。

至少这是错误的。

关于cocoa - NSBitmapImageRep 数据格式为应用程序图标图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2563533/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com