读取缓冲区中的png图像 [英] read a png image in buffer

查看:154
本文介绍了读取缓冲区中的png图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用libpng使用c将灰度png图像转换为原始图像.在该库中,函数 png_init_io 需要文件指针来读取png.但是我将png图像作为缓冲区传递,是否还有其他替代功能可以将png图像缓冲区读取为原始图像.请帮助我

hi i have used libpng to convert grayscale png image to raw image using c. in that lib the function png_init_io needs file pointer to read the png. but i pass the png image as buffer is there any other alternative functions to to read png image buffer to raw image. please help me

int read_png(char *file_name,int *outWidth,int *outHeight,unsigned char **outRaw)  /* We need to open the file */
{
......
/* Set up the input control if you are using standard C streams */
   png_init_io(png_ptr, fp);
......
}

相反,我需要这样的

int read_png(unsigned char *pngbuff, int pngbuffleng, int *outWidth,int *outHeight,unsigned char **outRaw)  /* We need to open the file */
{
}

推荐答案

摘自这样做,您可以愚弄png_init_io认为它正在从文件读取,而实际上您是在从缓冲区读取:

Doing this, you can fool png_init_io into thinking that it is reading from a file, while in reality you're reading from a buffer:

struct fake_file
{
    unsigned int *buf;
    unsigned int size;
    unsigned int cur;
};

static ... fake_read(FILE *fp, ...) /* see input and output from doc */
{
    struct fake_file *f = (struct fake_file *)fp;
    ... /* read a chunk and update f->cur */
}

struct fake_file f = { .buf = pngBuff, .size = pngbuffleng, .cur = 0 };
/* override read function with fake_read */
png_init_io(png_ptr, (FILE *)&f);

这篇关于读取缓冲区中的png图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆