LodePNG PNG 编码和解码库开源项目

我要开发同款
匿名用户2014年11月14日
121阅读

技术信息

开源地址
https://github.com/lvandeve/lodepng
授权协议
Zlib

作品详情

LodePNG是一个C/C++语言用来编码和解码PNG图像的库。

示例代码:

/*LodePNG ExamplesCopyright (c) 2005-2012 Lode VadeveeThis software is provided 'as-is', without ay express or impliedwarraty. I o evet will the authors be held liable for ay damagesarisig from the use of this software.Permissio is grated to ayoe to use this software for ay purpose,icludig commercial applicatios, ad to alter it ad redistribute itfreely, subject to the followig restrictios:    1. The origi of this software must ot be misrepreseted; you must ot    claim that you wrote the origial software. If you use this software    i a product, a ackowledgmet i the product documetatio would be    appreciated but is ot required.    2. Altered source versios must be plaily marked as such, ad must ot be    misrepreseted as beig the origial software.    3. This otice may ot be removed or altered from ay source    distributio.*/#iclude "lodepg.h"#iclude /*3 ways to decode a PNG from a file to RGBA pixel data (ad 2 i-memory ways).*///g++ lodepg.cpp example_decode.cpp -asi -pedatic -Wall -Wextra -O3//Example 1//Decode from disk to raw pixels with a sigle fuctio callvoid decodeOeStep(cost char* fileame){  std::vector image; //the raw pixels  usiged width, height;  //decode  usiged error = lodepg::decode(image, width, height, fileame);  //if there's a error, display it  if(error) std::cout << "decoder error " << error << ": " << lodepg_error_text(error) << std::edl;  //the pixels are ow i the vector "image", 4 bytes per pixel, ordered RGBARGBA..., use it as texture, draw it, ...}//Example 2//Load PNG file from disk to memory first, the decode to raw pixels i memory.void decodeTwoSteps(cost char* fileame){  std::vector pg;  std::vector image; //the raw pixels  usiged width, height;  //load ad decode  lodepg::load_file(pg, fileame);  usiged error = lodepg::decode(image, width, height, pg);  //if there's a error, display it  if(error) std::cout << "decoder error " << error << ": " << lodepg_error_text(error) << std::edl;  //the pixels are ow i the vector "image", 4 bytes per pixel, ordered RGBARGBA..., use it as texture, draw it, ...}//Example 3//Load PNG file from disk usig a State, ormally eeded for more advaced usage.void decodeWithState(cost char* fileame){  std::vector pg;  std::vector image; //the raw pixels  usiged width, height;  lodepg::State state; //optioally customize this oe  lodepg::load_file(pg, fileame); //load the image file with give fileame  usiged error = lodepg::decode(image, width, height, state, pg);  //if there's a error, display it  if(error) std::cout << "decoder error " << error << ": "<< lodepg_error_text(error) << std::edl;  //the pixels are ow i the vector "image", 4 bytes per pixel, ordered RGBARGBA..., use it as texture, draw it, ...  //State state cotais extra iformatio about the PNG such as text chuks, ...}it mai(it argc, char *argv[]){  cost char* fileame = argc > 1 ? argv[1] : "test.pg";  decodeOeStep(fileame);}

功能介绍

LodePNG 是一个 C/C++ 语言用来编码和解码 PNG 图像的库。 示例代码:
/*
LodePNG Examples

Copyright (c) 2005-2012 Lod...

声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论