c++ - 如何使用 Libwebp 从 Webp 解码和编码?

标签 c++ bitmap gdi+ webp image-formats

我在使用 C++ 中的 libwebp 从 webp 进行编码和解码时遇到了问题。 我构建了这个测试应用程序,它采用我创建的 webp 文件(在 chrome 中看起来不错),并尝试将其解码为 rgb,然后返回 webp,只是为了了解如何使用它,但输出是错误的:

//Code before reads the webp file, and assigning it to a uint8_t buffer called "pic" ///

WebPConfig config;
ASSERT(WebConfigIit(&config) == TRUE)

int width=0 height =0;
uint8_t * rgb = WebPDecodeRGB(pic, size, &width, &height)
ASSERT (rgb != NULL)
// At this point the width and the height is valid, and the rgb is assigned.

uint8_t* originalPic = null;
size_t size = WebPEncodeRGB(rgb, width, height, height, &originalPic);
// Didn't quite know what to put in the stride param.. 

/// Code after saves the originalPic buffer to a file ////

如您所见,我尝试做的只是设法对 webp 进行编码和解码,并尝试将其保存回文件,但当我尝试打开文件时,它看起来已损坏。

你能帮我找出问题所在吗? 此外,我很乐意了解更多关于步幅参数和 rgb 格式的信息,以及如何将图片转换为它以检查我的代码是否有效。

非常感谢!

最佳答案

WebPEncodeRGB 的第 4 个参数是步幅 (https://stackoverflow.com/a/2004638)。除非高度与步幅一致,否则传球高度可能不起作用。

关于c++ - 如何使用 Libwebp 从 Webp 解码和编码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28075464/

相关文章:

c++ - 具有堆对象和销毁冲突的数据类型的浅拷贝

android - 从另一个资源中绘制位图

gdi+ - 如何在gdi/gdi+中绘制柔和的线条

c# - 缩放到c#中的一个点

c++ - 如何用条件运算符表示三种情况?

C++11 正则表达式与字符串不匹配

c++ - 关于行列式计算的一段代码问题

java - 通过着色器获得晕影效果

android - 图像裁剪质量损失很大

c++ - Connect 4 板中的不均匀圆圈