我在使用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的第四个参数是跨度(https://stackoverflow.com/a/2004638)。除非高度与步幅一致,否则通过高度可能不起作用。

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

10-12 00:23
查看更多