Android:在 kmagick 中调整动画 gif 图像大小
我正在使用 kmagick 在 android 中调整 gif 图像的大小。它对于静态文件工作正常,但对于 gif 或动画 webp 文件给出不正确的输出。
Magick.initialize().use {
val wand = MagickWand()
// getting image
wand.readImage(src)
// resizing image
wand.resizeImage(512,512,FilterType.UndefinedFilter)
// Saving image
wand.writeImage(dst)
promise.resolve("Done at ${dst}")
}
输入:(具有多个帧的动画 gif)
输出:我认为它是单帧,而且也很混乱,但根据输入的高度宽度调整大小。
这里发生了什么。如何修复它?
I am using kmagick for resizing gif images in android. It works fine for static but gives incorretc output for gif or animated webp files.
Magick.initialize().use {
val wand = MagickWand()
// getting image
wand.readImage(src)
// resizing image
wand.resizeImage(512,512,FilterType.UndefinedFilter)
// Saving image
wand.writeImage(dst)
promise.resolve("Done at ${dst}")
}
Input: (animated gif having multiple frames)
Output: I think its single frame and that also messed up but resizes according to input for height width.
Whats happening here. How to fix it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只是想为将来提供参考,这个问题已经在
https://github.com/cherryleafroad/kmagick/issues/3#issuecomment- 1068044815
不管怎样,总结一下发生了什么,
Gif 能够保存帧之间的差异以节省空间。
这是由于 gif 图像的工作方式所致。因为cli以一定的方式使用api,而kmagick绑定只是直接绑定到c api,所以如果你想达到与cli相同的结果,你必须以同样的方式使用api。 (kmagick 没有对图像做任何事情,是 imagemagick 做的;所以检查 imagemagick api 文档/询问他们更相关,这样你就可以用同样的方式做并得到相同的结果)。
我不确定他们使用什么 imagemagick api 来实现这些结果,但我认为单独提取每个帧然后一一调整它们的大小可以解决这个问题。
Just want to reference for future, this was already answered in
https://github.com/cherryleafroad/kmagick/issues/3#issuecomment-1068044815
Anyways, to sum up what's going on,
Gifs are able to save the difference between frames to save space.
It's due to the way gif images work. Because the cli uses the api in a certain way, and kmagick bindings are only direct bindings to the c api, if you want to achieve the same results that the cli does, you have to use the api in the same way. (kmagick isn't doing anything to the image, it's imagemagick that's doing it; so it's more relevant to check imagemagick api docs / ask them so you can do it in the same way and get the same results).
I'm not sure what imagemagick api they're using off the top of my head however to achieve those results, but I think that doing something like extracting each frame individually then resizing them one by one would solve it.