为什么Flutter(飞镖)处理图像的速度如此之慢? [英] Why Flutter (dart) is so slow to process images?

查看:282
本文介绍了为什么Flutter(飞镖)处理图像的速度如此之慢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这种方法,可以将用户手机中的照片加载到内存中,调整大小并将其编码为JPEG:

I have this method, that loads a photo from the user's phone to memory, resizes it and encodes it as JPEG:

List<int> processPersonProfilePhoto(File file) {
  var rawPhoto = file.readAsBytesSync();
  var jpg = Image.decodeJpg(rawPhoto);
  jpg = Image.copyResize(jpg, 512);
  return Image.encodeJpg(jpg, quality: 70);
}

我正在通过以下方法在单独的隔离上运行上述方法:

I am running the method above on a separated isolate, via:

var jpgByteArray = await compute(processPersonProfilePhoto, file);

整个过程有时需要20到30秒(发布模式比调试还要差),我

This whole process sometimes takes 20 - 30 seconds (the release mode is even worse than debug) and I am running on middle and high end devices.

这是我正在处理的软件包:

This is the package I am using to process:

image: ^2.0.7

我在做什么错?

PS .:我做了更多的调试工作,并意识到需要花费更长时间处理的那行是去尾的:

PS.: I done some more debugging and realized that the line that takes much longer to process is the deconding one:

var jpg = Image.decodeJpg(rawPhoto);


推荐答案

我发现这是一个图书馆问题。您可以在lib的github页面上跟踪问题,很多问题抱怨运行缓慢。 ( https://github.com/brendan-duncan/image/issues/104

I found out that this is a library issue. You can track the problem on the lib's github page, there are a lot of issues complaining about the slowness. (https://github.com/brendan-duncan/image/issues/104)

在修复之前,请使用该库:
https://pub.dartlang.org/packages/flutter_image_compress

Until it gets fixed, use that library instead: https://pub.dartlang.org/packages/flutter_image_compress

编辑:似乎图书馆已经修复了RELEASE构建上的速度缓慢问题: https://github.com/brendan- duncan / image / issues / 104#issuecomment-490794535

Seems now that the library has fixed the slowness problem on RELEASE builds: https://github.com/brendan-duncan/image/issues/104#issuecomment-490794535

这篇关于为什么Flutter(飞镖)处理图像的速度如此之慢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆