有没有办法获得图像的rgb矩阵表示?反之亦然?我想对原始图像执行图像屏蔽/过滤,因此需要将其应用于其rgb矩阵表示。目前正在使用此库从设备获取图像:https://pub.dartlang.org/packages/image_picker
答案 0 :(得分:3)
https://pub.dartlang.org/packages/image提供图像转换和操作实用程序功能。
答案 1 :(得分:0)
import 'dart:ui' as ui;
import 'package:flutter/material.dart';
// for a local iamge example
List RGBAList;
// 1. get [ImageProvider] instance
// [ExactAssetImage] extends [AssetBundleImageProvider] extends [ImageProvider]
ExactAssetImage provider = ExactAssetImage('$local_img_uri');
// 2. get [ui.Image] by [ImageProvider]
ImageStream stream = provider.resolve(ImageConfiguration.empty);
Completer completer = Completer<ui.Image>();
ImageStreamListener listener = ImageStreamListener((frame, sync) {
ui.Image image = frame.image;
completer.complete(image);
stream.removeListener(listener);
})
stream.addListener(listener);
// 3. get rgba array/list by [ui.Image]
completer.then((ui.Image image) {
image.toByteData(format: ui.ImageByteFormat.rowRgba).then((ByteData data) {
RGBAList = data.buffer.asUint8List().toList();
});
})