Jae*_*Kim 5 resize image flutter
我正在尝试从 uint8list 数据更改图像大小。
众所周知,Flutter 中有很多 Image 类,我想要获得的最终图像类型是 ui.Image。
我从套接字通信中获取 Uint8List Image(.jpg) 数据。
现在,我想设置图像的大小并在最后获取 ui.Image 的图像。
我试图通过 (dart:ui : ui, package:image/image.dart : IMG) 做到这一点
IMG.Image img = IMG.decodeImage(data);
IMG.Image resized = IMG.copyResize(img, width: 400, height: 200);
ui.Codec codec = await ui.instantiateImageCodec(IMG.encodeJpg(resized));
ui.Image image = (await codec.getNextFrame()).image;
Run Code Online (Sandbox Code Playgroud)
,但它冻结了应用程序。
我怎样才能做到这一点?有什么办法吗?谢谢你。
另外,
在“flutter/lib/src/widgets/image.dart”中,
Image.memory(Uint8List, width, height)
可以轻松设置图片大小。有什么办法可以从那个 Image 小部件中获取 Uint8List 吗?
Jae*_*Kim 11
我调整了 Uint8List 中图像数据的大小,如下所示。
import package:image/image.dart as IMG
Uint8List resizeImage(Uint8List data) {
Uint8List resizedData = data;
IMG.Image img = IMG.decodeImage(data);
IMG.Image resized = IMG.copyResize(img, width: img.width*2, height: img.height*2);
resizedData = IMG.encodeJpg(resized);
return resizedData;
}
Run Code Online (Sandbox Code Playgroud)
IMG : flutter 镜像包
您是否尝试过使用andui.decodeImageFromList
代替?ui.instantiateImageCodec
getNextFrame()
import 'dart:ui' as ui;
ui.decodeImageFromList(IMG.encodeJpg(resized), (ui.Image img) {
// returned ui.Image
});
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1507 次 |
最近记录: |