我在使用 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/