问题描述
我的目标是加载 PNG 文件以供查看。我做了以下仪式:
png_get_IHDR(png_ptr,info_ptr,&width,&height,&bit_depth,&color_type,&interlace_type,NULL,NULL);
if (bit_depth == 16)
{
/* strip it down to 8-bit */
png_set_strip_16(png_ptr);
}
/* we do not want interlaced image data */
png_set_interlace_handling(png_ptr);
if (color_type == PNG_COLOR_TYPE_PALETTE)
{
/* we need raw color values,no palette */
png_set_palette_to_rgb(png_ptr);
}
if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
{
/* always expand 1,2 or 4 bit grey maps to full 8-bits */
png_set_expand_gray_1_2_4_to_8(png_ptr);
}
if (png_get_valid(png_ptr,PNG_INFO_tRNS))
{
/* realize transparency in the alpha */
png_set_tRNS_to_alpha(png_ptr);
}
if (color_type == PNG_COLOR_TYPE_RGB
|| color_type == PNG_COLOR_TYPE_GRAY
|| color_type == PNG_COLOR_TYPE_PALETTE)
{
/* if the color type does not have an alpha,make it have an alpha of 0xFF */
png_set_add_alpha(png_ptr,0xFF,PNG_FILLER_AFTER);
}
if (color_type == PNG_COLOR_TYPE_GRAY || color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
{
/* expand grey to RGB */
png_set_gray_to_rgb(png_ptr);
}
我猜测使用 png_read_image()
将提供 sRGB 像素,但我不知道。我也看到了 png_set_sRGB()
函数,但我猜测用于何时写入 PNG 文件。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)