我正在使用 flutter-ffmpeg 包将图像覆盖到视频上,覆盖后我在该图像上绘制一个矩形,但问题是,ffmpeg 使用真实像素数据覆盖图像,而 flutter 使用逻辑像素绘制矩形,所以如何将 ffmpeg 的真实像素转换为 flutter 的逻辑像素,以便我可以更改图像的覆盖尺寸以与矩形匹配。
最佳答案
您可以使用devicePixelRatio 。以下是 Flutter 文档中的定义:
The number of device pixels for each logical pixel. This number might not be a power of two. Indeed, it might not even be an integer. For example, the Nexus 6 has a device pixel ratio of 3.5.
Device pixels are also referred to as physical pixels. Logical pixels are also referred to as device-independent or resolution-independent pixels.
因此,devicePixels/WidgetsBinding.instance.window.devicePixelRatio
应该为您提供逻辑像素。
关于flutter - 如何将真实像素值转换为 flutter 逻辑像素(密度独立像素),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60900250/