我正在尝试使用C读取PNG文件以与OpenCL一起使用.OpenCL不支持24位RGB图像,因此我需要将数据从RGB扩展到RGBA.我使用的PNG都是24位的,因此可以避免头痛.
我试图使用png_set_filler和png_set_add_alpha,我认为它们大致完全相同以解决问题,但它们都会导致此错误:
libpng error: sequential row overflow
Run Code Online (Sandbox Code Playgroud)
这是完整的功能:
int LoadPNG24(unsigned char ** pixelBuffer, const char *filename, unsigned int *width, unsigned int *height) {
png_byte header[8];
//open file as binary
FILE *fp = fopen(filename, "rb");
if (!fp) {
return TEXTURE_LOAD_ERROR;
}
//read the header
fread(header, 1, 8, fp);
//test if png
int is_png = !png_sig_cmp(header, 0, 8);
if (!is_png) {
fclose(fp);
return TEXTURE_LOAD_ERROR;
}
//create png struct
png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (!png_ptr) {
fclose(fp);
return (TEXTURE_LOAD_ERROR);
} …
Run Code Online (Sandbox Code Playgroud) 我的应用程序被终止,并且日志:libpng警告:忽略错误的自适应过滤器类型。我想知道原因,以及解决办法。
我在使用 CMake 在 OSX 上构建 C++ 项目时遇到了一个相当奇怪的问题,同时将 libpng 作为依赖项引入。我通过自制软件安装了 libpng 1.6.21 和以下 CMake 规则:
FIND_PACKAGE(PNG REQUIRED)
INCLUDE_DIRECTORIES(${PNG_INCLUDE_DIRS})
LINK_DIRECTORIES(${PNG_LIBRARY_DIRS})
ADD_DEFINITIONS(${PNG_DEFINITIONS})
Run Code Online (Sandbox Code Playgroud)
当 CMake 开始构建并找到依赖项时,它输出:
-- Found PNG: /usr/local/lib/libpng.dylib (found version "1.4.12")
Run Code Online (Sandbox Code Playgroud)
进一步调查,/usr/local/lib/libpng.dylib
是 brew 1.6 版本的符号链接:
$ ls -l /usr/local/lib/libpng.dylib
lrwxr-xr-x 1 fluffy admin 40 Apr 9 16:06 /usr/local/lib/libpng.dylib -> ../Cellar/libpng/1.6.21/lib/libpng.dylib
Run Code Online (Sandbox Code Playgroud)
但是,似乎png.h
包含的内容不正确,因为PNG_LIBPNG_VER_STRING
在启动输出时打印出来1.4.12
。而且,当然,当我尝试运行我的程序时,我发现版本不匹配并且库无法工作:
libpng warning: Application built with libpng-1.4.12 but running with 1.6.21
libc++abi.dylib: terminating with uncaught exception of type std::runtime_error: [write_png_file] png_create_write_struct failed
Run Code Online (Sandbox Code Playgroud)
使用 时 …
我正在尝试在我的 Mac 上安装该reticulate
软件包,它取决于该png
软件包,而该软件包又取决于libpng
. 我安装了libpng
brew ,但png
由于缺少以下内容而导致包失败libpng-config
:
/bin/sh: libpng-config: command not found
Run Code Online (Sandbox Code Playgroud)
不过我有这个/opt/homebrew/bin/libpng-config
:
which libpng-config
/opt/homebrew/bin/libpng-config
Run Code Online (Sandbox Code Playgroud)
我发现这个指定了需要libpng-dev
,但我不知道如何在我的 Mac 上安装它。任何帮助表示赞赏。
基本上我想使用libpng将位图转换为png,而不是将其输出到FILE*我想将它输出到char*.我已经看过这个相关的帖子,但我没看到实际使用位图数据的位置.任何帮助,将不胜感激.
我无法使用CImg加载PNG.我听说你需要让libpng/zlib先上班,但我不确定如何设置它.我在Ubuntu上.我的来源:
#include <cmath>
#include <cstdio>
#include <string>
#include <assert.h>
#include <stdarg.h>
#define cimg_using_png
#include "CImg.h"
using namespace cimg_library;
#include "png.h"
int main(int argc, char** argv)
{
CImg<unsigned char> img2("test.png");
img2.display();
return 0;
}
Run Code Online (Sandbox Code Playgroud) 如何知道调色板png是否带有alpha?我得到有关图像的信息png_get_IHDR
之后我看看 color_type - PNG_COLOR_TYPE_PALETTE
但我无法找到如何知道这个png图像是否有alpha通道.
我正试图在vs2013中使用libpng 1.2.10读取一个png文件.我下载了最新的zlib并编译了pnglib,效果很好.现在我正在尝试加载文件:
int *w = &width;
int *h = &height;
const char* name = file.c_str();
FILE *png_file = fopen(name, "rb");
if (!png_file)
{
std::cerr << "Could not open " + file << std::endl;
return;
}
unsigned char header[PNG_SIG_BYTES];
fread(header, 1, PNG_SIG_BYTES, png_file);
if (png_sig_cmp(header, 0, PNG_SIG_BYTES))
{
std::cerr << "PNG signature fail " + file << std::endl;
return;
}
png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if(png_ptr == NULL)
{
std::cerr << "PNG read fail " + file << std::endl; …
Run Code Online (Sandbox Code Playgroud) 我在OS X Yosemite上运行MAMP服务器版本3.0.5.在执行期间我的php文件似乎缺少PNG支持即使在我使用MAMP 2.1之前,它在png相关函数上也有致命错误.
Jpeg函数工作正常.
这就是我的phpinfo的样子:
Build Date Apr 10 2014 17:21:18
Configure Command './configure' '--with-mysql=/Applications/MAMP/Library' '--with-apxs2=/Applications/MAMP/Library/bin/apxs' '--with-gd' '--with-jpeg-dir=/Applications/MAMP/Library' '--with-png-dir=/Applications/MAMP/Library' '--with-zlib' '--with-zlib-dir=/Applications/MAMP/Library' '--with-freetype-dir=/Applications/MAMP/Library' '--prefix=/Applications/MAMP/bin/php/php5.5.10' '--exec-prefix=/Applications/MAMP/bin/php/php5.5.10' '--sysconfdir=/Applications/MAMP/bin/php/php5.5.10/conf' '--with-config-file-path=/Applications/MAMP/bin/php/php5.5.10/conf' '--enable-ftp' '--enable-gd-native-ttf' '--with-bz2=/usr' '--with-ldap' '--with-mysqli=/Applications/MAMP/Library/bin/mysql_config' '--with-t1lib=/Applications/MAMP/Library' '--enable-mbstring=all' '--with-curl=/Applications/MAMP/Library' '--enable-sockets' '--enable-bcmath' '--with-imap=shared,/Applications/MAMP/Library/lib/imap-2007f' '--enable-soap' '--with-kerberos' '--enable-calendar' '--with-pgsql=shared,/Applications/MAMP/Library/pg' '--enable-exif' '--with-libxml-dir=/Applications/MAMP/Library' '--with-gettext=shared,/Applications/MAMP/Library' '--with-xsl=/Applications/MAMP/Library' '--with-pdo-mysql=shared,/Applications/MAMP/Library' '--with-pdo-pgsql=shared,/Applications/MAMP/Library/pg' '--with-mcrypt=shared,/Applications/MAMP/Library' '--with-openssl' '--enable-zip' '--with-iconv=/Applications/MAMP/Library' '--enable-opcache' '--enable-intl' '--with-tidy=shared' '--with-icu-dir=/Applications/MAMP/Library'
Run Code Online (Sandbox Code Playgroud)
这就是GD部分包含的内容:
GD Support enabled
GD Version bundled (2.1.0 compatible)
FreeType Support enabled
FreeType Linkage with freetype
FreeType Version 2.4.12
T1Lib Support enabled
GIF Read …
Run Code Online (Sandbox Code Playgroud) 在Android Studio中编译我的应用程序以进行调试时,我收到以下错误:
Failed to run command:
C:\Users\Farbod\Android-SDK\build-tools\21.1.2\aapt.exe s -i C:\Users\Farbod\AndroidStudioProjects\MyApp\app\src\main\res\drawable-hdpi\img_myImage.png -o C:\Users\Me\AndroidStudioProjects\MyApp\app\build\intermediates\res\debug\drawable-hdpi-v4\img_myImage.png
Error Code:
42
Output:
C:\Users\Me\AndroidStudioProjects\MyApp\app\src\main\res\drawable-hdpi\img_myImage.png: libpng warning: IDAT: Too many IDATs found
libpng error: Read Error
:app:mergeDebugResrouces FAILED
Run Code Online (Sandbox Code Playgroud)
我已经检查过我的所有文件都是.png
格式,我不确定是什么原因.