这是一段获得256色象调色板信息的代码
INT main()
{
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); Image* image = new Image(L"Stripes8Bit.bmp"); UINT size = image->GetPaletteSize();
printf("The size of the palette is %d bytes.\n", size);
ColorPalette* palette = (ColorPalette*)malloc(size); image->GetPalette(palette, size); if(size > 0)
{
printf("There are %u colors in the palette.\n", palette->Count);
printf("The first five colors in the palette are as follows:\n"); for(INT j = 0; j <= 4; ++j)
printf("%x\n", palette->Entries[j]);
} delete(image);
free(palette);
GdiplusShutdown(gdiplusToken);
return 0;
}
下面是msdn例子上的输出结果
The preceding code, along with a particular file, Stripes8Bit.bmp, produced the following output:The size of the palette is 1032 bytes.
There are 256 colors in the palette.
The first five colors in the palette are as follows:
ff000000
ff800000
ff008000
ff808000
ff000080
它用的是一个8位的bmp,我换成一个8位的png,其他都一样,结果得到color为0?什么道理。。
The size of the palette is 12 bytes.
There are 0 colors in the palette.
The first five colors in the palette are as follows:
0
fdfdfdfd
0
0
41
INT main()
{
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL); Image* image = new Image(L"Stripes8Bit.bmp"); UINT size = image->GetPaletteSize();
printf("The size of the palette is %d bytes.\n", size);
ColorPalette* palette = (ColorPalette*)malloc(size); image->GetPalette(palette, size); if(size > 0)
{
printf("There are %u colors in the palette.\n", palette->Count);
printf("The first five colors in the palette are as follows:\n"); for(INT j = 0; j <= 4; ++j)
printf("%x\n", palette->Entries[j]);
} delete(image);
free(palette);
GdiplusShutdown(gdiplusToken);
return 0;
}
下面是msdn例子上的输出结果
The preceding code, along with a particular file, Stripes8Bit.bmp, produced the following output:The size of the palette is 1032 bytes.
There are 256 colors in the palette.
The first five colors in the palette are as follows:
ff000000
ff800000
ff008000
ff808000
ff000080
它用的是一个8位的bmp,我换成一个8位的png,其他都一样,结果得到color为0?什么道理。。
The size of the palette is 12 bytes.
There are 0 colors in the palette.
The first five colors in the palette are as follows:
0
fdfdfdfd
0
0
41
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货