在C中使用loadpng在BMP和PNG格式之间进行转换

问题描述 投票:0回答:1

我在 Windows 10 平台上使用 Visual Studio 2022,并希望在 C 中在 BMP 和 PNG 图像格式之间进行转换。这是因为我有一些处理 BMP 图像中像素的应用程序,并希望将最终图像转换为 PNG 格式,同样输入PNG图像并将其转换为BMP格式。这是专门针对没有 Alpha 通道的 24 位 RGB 图像。有在线图像转换器、Adobe 软件可以做到这一点,我相信 Windows 实用程序也可以做到这一点。但是,我希望将此类转换软件合并到我的项目中,而无需外部依赖或使用特定操作系统。

LoadPng 似乎符合要求,从链接 https://lodev.org/lodepng/ 我下载了文件 loadpng.c 和 loadpng.h 并将它们放入 Visual Studio 项目中。我还将 example_decode.c 和 example_encode.c 中的代码复制到项目中的 main 函数中,并使用条件编译来选择编码或解码,现在作为测试,我选择了编码并使用encodeOneStep() 函数进行测试。有encodeTwoSteps()和encodeWithState()函数没有被调用。

无论如何,在调试模式下使用 x64 选项进行编译时,我会收到完整的警告消息列表。前两个是

lodepng.c(712,54): warning C4334: '<<': result of 32-bit     shift implicitly converted to 64 bits (was 64-bit shift intended?)
lodepng.c(730,28): warning C4267: '=': conversion from 'size_t' to 'unsigned short', possible loss of data

还有很多其他类似这两个警告。修复像第二个这样的警告应该相对容易,但是如何修复像第一个这样的警告呢?顺便说一句,文件 loadpng.c 中的行号与下载的相同,因为该文件尚未编辑。

当我运行该程序时,它确实可以工作并生成测试输出图像。不管怎样,我想摆脱这些警告消息。

当我在调试模式下使用 x86 选项编译项目时,所有第一种类型的警告消息,即“'<<': result of 32-bit" disappear, and most of the warnings of the second type also disappear, but a few still appear as "conversion from 'size_t' to 'unsigned short'". Again, the application runs correctly. However, this is an aside, as I wish to stick to 64-bit (x64) compilation.

最后,虽然LoadPng中的示例是针对RGBA图像设置的,但假设上述问题可以解决,我打算使用RGB图像的代码。有人可以给我关于如何修复代码的建议,以便 x64 编译的警告消息不会出现 - 非常感谢。

c png bmp
1个回答
0
投票

访问 lodev.org,您会注意到“使用示例”下的以下链接:

example_png2bmp.cpp:将PNG转换为BMP example_bmp2png.cpp:将 BMP 转换为 PNG

考虑到手头的问题突然结束,您可能已经找到了这两个链接,但对于其他人来说,这就是您想要开始的地方。

© www.soinside.com 2019 - 2024. All rights reserved.