大家好,
最近研究C语言图像处理这方面遇到一个难题,详情如下:
目标: 将png类型图片的信息读入内存,提取所需要的数据并保存,然后转换为如jpg等其它图片格式。
1. libpng库已经装好,通过makefile调用库文件路径也正确。
2. 写了一个读取函数, 如下:
#include
#include
#include
#include
#include
#include
#include "png.h"
#include "pngio.h"
#include "error.h"
#include "image.h"
/*==============================================================================*
* read_png *
*==============================================================================*/
int x, y;
int width, height;
int channels;
png_byte color_type;
png_byte bit_depth;
png_structp png_ptr;
png_infop info_ptr;
int number_of_passes;
png_bytep *row_pointers;
png_uint_32 w, h;
size_t npixels;
//png_uint_32* raster;
//png_uint_32
int read_png (char * input_filename, picture *thePicture, FILE *status_log)
{
int err = no_err;
char header[8]; // 8 is the maximum size that can be checked
/* open file and test for it being a png */
FILE *fp = fopen(input_filename, "rb");
if (fp