gpt4 book ai didi

c++ - Linux 上的 FreeImage 返回 -1 格式

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:39:20 24 4
gpt4 key购买 nike

我很高兴使用 Ubuntu 16.04 LTS。不久前,我尝试从 sourceforge page 构建 FreeImage的免费图像。后来我完全卸载了它并通过 apt-get 安装了相同的版本

sudo apt-get install libfreeimage3

命令。虽然,问题是一样的。我在 Linux 版本的 Mono 中使用 FreeImage,但问题仍然存在,即使是 C++ 代码。假设我们有 ma​​in.cpp 文件,其中的代码如下:

#include <FreeImage.h>
#include <iostream>

using namespace std;

int main()
{
FreeImage_Initialise();
FREE_IMAGE_FORMAT format = FreeImage_GetFIFFromFilenameU(L"/home/nikys/1.jpg");
cout << format << endl;
FreeImage_DeInitialise();
}

像这样编译后(在类似“apt-get”的安装后,我将库的链接添加到/usr/lib,因此可以找到它):

g++ -I. -c main.cpp -o main.o -lc -lfreeimage
g++ main.o -o main -lc -lfreeimage

我收到 .exr 和 .jpg 文件的结果“-1”。

事情是,我在 Windows 上有 .NET 的 FreeImage 库,它为相同的对象返回正确的格式(Linux Mono 上的相同代码,与上述共享对象链接,也给了我“-1”,没有任何 DllNotFoundException 或 EntryPointNotFound ).可能出了什么问题?请求信息,因为我肯定忘记提及重要信息。

UPD1:如果我使用

FREE_IMAGE_FORMAT format = FreeImage_GetFIFFromFilename("/home/nikys/1.jpg");

FREE_IMAGE_FORMAT format = FreeImage_GetFileType("/home/nikys/1.jpg");

我很高兴,并且像正常人一样拥有“2”。虽然,对于宽字符串或 FreeImage_GetFileTypeU,FreeImage_GetFIFFromFilenameU 都不会告诉我正确的结果。 :(

最佳答案

Linux 对文件和输入使用 UTF8 编码,而不是宽字符串。

为了使您的代码在不同的操作系统中工作,您需要将一些命令包含在 #if defined(OS1)...#else... 中,或者使用像 Qt 这样的多操作系统 API或 wxWidgets。

关于c++ - Linux 上的 FreeImage 返回 -1 格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44571143/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com