http://www.cnblogs.com/mr-wid/archive/2013/04/19/3029842.html
先看这篇文章,关于pnglib的入门讲解
下面贴上源代码(在VC 6.0下编译通过):
#include "stdafx.h"
#include <stdio.h>
#include "png.h"
#include <stdlib.h>
typedef struct {
unsigned char* pixelData;
int imageWidth;
int imageHeight;
}ImageInfo;
typedef struct {
unsigned char* data;
int size;
int offset;
}ImageSource;
ImageInfo* decodePNGFromFile(char* fileName)
{
char png_header[8];
png_structp png_ptr;
png_infop info_ptr;
int width, height, rowBytes;
png_byte color_type;
png_byte bit_depth;
png_colorp palette;
/* open file and test for it being a png */
FILE *file = fopen(fileName, "rb");
fread(png_header, 1, 8, file);
if(png_sig_cmp((png_bytep)png_header, 0, 8))
{

这篇博客介绍了如何使用C++和libpng库从PNG文件中解码并获取RGBA像素数据。通过创建和初始化png_structp和png_infop结构,然后调用png_read_png()函数来读取PNG图像。博主展示了如何处理原始数据,以适应OpenGL ES纹理绘制的要求,特别注意了从顶部到底部的像素存储顺序。最后,博主提供了从解码的PNG数据中提取特定通道(如Alpha)的示例代码。

2632

被折叠的 条评论
为什么被折叠?



