简体   繁体   English

Flutter ui.ImageByteFormat.rawRgba 的图像质量很差

[英]Flutter ui.ImageByteFormat.rawRgba has terrible Image Quality

In my project, I need to capture the frame of a flutter animation and save that frame as an image (probably in.png) to Device Storage.在我的项目中,我需要捕获 flutter animation 的框架并将该框架作为图像(可能是 in.png)保存到设备存储。

I am using RepaintBoundary to capture the frame, but I can't use the ui.ImageByteFormat.png method because it takes a lot of process time to capture the frame as a.png, and since I need to take a lot of frames it will not be a viable solution.我正在使用 RepaintBoundary 来捕获帧,但我不能使用ui.ImageByteFormat.png方法,因为将帧捕获为 a.png 需要很多处理时间,而且由于我需要拍摄很多帧不会是一个可行的解决方案。 Instead, I am using ui.ImageByteFormat.rawRgba which is super fast but when I save it to Storage the image quality is terrible.相反,我使用的是超级快的ui.ImageByteFormat.rawRgba ,但是当我将其保存到 Storage 时,图像质量很糟糕。 It hardly looks like it's the same image I captured.它看起来几乎与我捕获的图像相同。

I am using FFMPEG to convert.raw or.bmp format to png and save it to storage.我正在使用 FFMPEG 将 .raw 或 .bmp 格式转换为 png 并将其保存到存储中。

In both cases, using raw or using BitMap the output image is like this:在这两种情况下,使用 raw 或使用 BitMap output 图像是这样的:

在此处输入图像描述

But, the Quality of the Image should be like this但是,图像的质量应该是这样的在此处输入图像描述

Now, I need help to either get this raw capture saved with quality by using whatever file format doesn't matter or please share if you have any other viable method to capture frames of a flutter animation.现在,我需要帮助以通过使用无关紧要的任何文件格式保存此原始捕获,或者如果您有任何其他可行的方法来捕获 flutter animation 的帧,请分享。

IMHO, that's not about quality (eg a "blur" image is of bad quality).恕我直言,这与质量无关(例如,“模糊”图像质量差)。 that's because there are some problems on the format - someone must wrongly understand the format when encoding/decoding it.那是因为格式上存在一些问题 - 编码/解码时必须有人错误地理解格式。

After looking at your code, it is likely that, your Bitmap.fromHeadless(300,100,bytes) has problem.查看您的代码后,您的Bitmap.fromHeadless(300,100,bytes)很可能有问题。 The image is not 300x100.图像不是 300x100。 Please correct the size.请更正尺寸。

Let me explain a bit about the "raw" or "bmp" format.让我解释一下“原始”或“bmp”格式。 Basically, the format just put pixels one after one onto a big list of bytes.基本上,该格式只是将像素一个接一个地放到一个大字节列表中。 For example, the array looks like: ["red at (0,0)", "green at (0,0)", "blue at (0,0)", "alpha at (0,0)", "red at (0,1)", "green at (0,1)", "blue at (0,1)", "alpha at (0,1)", ...] .例如,数组看起来像: ["red at (0,0)", "green at (0,0)", "blue at (0,0)", "alpha at (0,0)", "red at (0,1)", "green at (0,1)", "blue at (0,1)", "alpha at (0,1)", ...] Notice it is row major order.请注意,这是行主要订单。 In other words, the order is like "pixel0,0", "pixel0,1", ... "pixel0,k", "pixel1,0", ...换句话说,顺序就像 "pixel0,0", "pixel0,1", ... "pixel0,k", "pixel1,0", ...

Thus, if you specify the wrong size, then it will be interpreted wrongly - That's why you see that strange-looking image!因此,如果你指定了错误的尺寸,那么它就会被错误地解释——这就是你看到那个奇怪的图像的原因!

About how to get size: After your line of ui.Image image = await boundary.toImage(pixelRatio: 3);关于如何获取大小:在你的ui.Image image = await boundary.toImage(pixelRatio: 3);行之后, you can simply do image.width and image.height to get the correct size. ,您可以简单地执行image.widthimage.height来获得正确的大小。

Please reply if you do not understand something and I am willing to explain;)如果您有不明白的地方请回复,我愿意解释;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM