2012-11-23 4 views
0

I에 일부 png 이미지가 있습니다. 내가 열어. 내가 파일로 저장하는 것보다. 그리고 저장된 이미지를 열려고하면 문제가 생깁니다. 의 libpng 오류 :의 libpng/example.c에 도시 된 바와 같이libpng 오류 : 읽기 오류

png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); 
png_infop info_ptr = png_create_info_struct(png_ptr); 
//created png struct 

setjmp(png_jmpbuf(png_ptr)) 
//signed 
png_init_io(png_ptr, file); 

png_set_IHDR(png_ptr, info_ptr, width, height, 8, PNG_COLOR_TYPE_RGBA, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); 
//set header 
unsigned char * buffer = (unsigned char*)malloc(4 *width * height); 
// created buffer 
unsigned char ** row_pointers = (unsigned char**) malloc(height * sizeof(unsigned char *)); // created rows pointers 
for (int i= 0; i< height ; i++) { 
    row_pointers[i] = buffer + i * 4 * width; 
} 

memset(buffer, 255, 4 * height * width); // fill buffer with white image for example. 
// **I mean that the same problem is even when i do not write the opened image, 
//but just fill it with white**. 

png_write_image(png_ptr, row_pointers); 
//write data 

png_write_end(png_ptr, NULL); 

png_destroy_write_struct(&png_ptr, (png_infopp)NULL); 
+0

여기

png_read_rows에 읽기 오류는 코드를 작성하는 것입니다 당신은 다른 리더/뷰어로 generaetd png 파일을 열려고 했습니까? 그건 당신이 문제를 좁히는 데 도움이 될 것입니다 – leonbloy

+0

그 파일도 거기에 손상된 것을 볼 수 있습니다. –

답변

0

(png_set_IHDR 후이를 넣어) :

// Write the file header information. REQUIRED 

png_write_info(png_ptr, info_ptr);