2010-04-01 44 views
0

我有一個char *數組,在RGBA,然後移動到ARGBNSBitmapImageRep數據格式爲應用程序圖標圖像?

底線是設置的應用程序圖像看起來完全搞砸了,我不能把我的手指爲什麼?

//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(掃描線)後,這是我得到的圖像。 ![alt text] [1]

原始圖像只是一個橙色的正方形。

EDIT2:更新的圖像和一些參數。

謝謝!

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

+0

不要忘記釋放或自動釋放圖像代表。 – 2010-04-03 21:01:52

回答

1

這是爲bytesPerRow指定爲0,如果你也傳遞NULL的數據(從而讓代表分配它本身)時纔有用。如果通過零,則要求系統使用「最佳」bytesPerRow,這在架構和操作系統版本之間並不穩定。它不是寬度* bitsPerPixel,它被填充以便對齊。

這是一個那是錯誤的,至少。

+0

我添加了一個編輯以包含您的更改,結果已發佈,謝謝!差不多了。 – Joe 2010-04-01 21:50:36

+0

呃,32位也是PerPixel。如果你傳遞數據,數據的格式已經確定,所以你不應該讓框架選擇任何東西。除此之外,我想我會懷疑數據是否真的是你傳遞給位圖的格式。你可能需要附上一個完整的示例應用程序喲讓人看到。 – Ken 2010-04-01 22:06:24

+0

我希望我能...我補充說,以及它看起來差不多一樣...我知道數據是正確的,因爲我在Windows上使用它。 雖然這是char **,但是使它無符號變得奇怪嗎?我不認爲它應該。感謝您的建議 – Joe 2010-04-01 22:23:04

相關問題