【问题标题】:writing a PNG in grayscale or RGB in C with libpng使用 libpng 在 C 中以灰度或 RGB 格式编写 PNG
【发布时间】:2013-08-03 08:28:54
【问题描述】:

我正在尝试使用libpng in C 从可以是灰度(8bits*1componant)或 rgb(8bits*3componant)的图像写入 PNG 文件。

我阅读了手册并编写了这段不起作用的代码:-/

/* writing the image */
png_byte *row_pointers[img->height];
int h;
for (h = 0 ; h < img->height ; h++)
{
    row_pointers[h] = img->data+h*img->width*image_components;
}
png_write_image(png_ptr, row_pointers);

图像中没有写入任何内容,我不明白为什么。

img.data指向图像数据(RGB格式情况下交错)

【问题讨论】:

    标签: c image-processing rgb grayscale libpng


    【解决方案1】:

    文档说您应该使用 png_write_end,请参阅http://www.libpng.org/pub/png/libpng-1.2.5-manual.html 中的“完成顺序写入”部分。 那里有很多例子(例如http://zarb.org/~gc/html/libpng.html

    【讨论】:

    • 我使用的时候,除了空的png文件,还有这个错误libpng error: No IDATs written into file
    • 如果直接使用会怎样:png_write_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL);反而?它对我有用,我能够在使用 png_write_image 和 png_write_end 时复制您的错误。但是,我使用的示例之前也运行了其他功能(例如创建 info_ptr 内容、png_set_IHDR,...)。
    猜你喜欢
    • 2020-12-23
    • 2016-09-07
    • 2021-04-11
    • 1970-01-01
    • 2011-06-02
    • 1970-01-01
    • 2020-02-24
    • 2019-04-10
    • 1970-01-01
    相关资源
    最近更新 更多