我想创建一个使用惰性像素更新技术的查看器,以观看帧之间像素变化较小的实时视频(例如,在线讲座中的鼠标指针和绘图工具)
我发现该库很好地用于图像处理和更新框架,但是我无法使用它在Widget中显示图像。
https://pub.dartlang.org/packages/image
我尝试使用图像字节(尽管此方法很慢)
Image.memory (myImage.getBytes ());
但是我有这个例外
[ERROR:flutter/lib/ui/painting/codec.cc(97)] Failed decoding image. Data is either invalid, or it is encoded using an unsupported format.
我的代码:
import 'dart:math';
import 'dart:typed_data';
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:image/image.dart' as img;
void main() => runApp(
new MaterialApp(
home: new HomePage(),
));
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => new _HomePageState();
}
class _HomePageState extends State<HomePage> {
Uint8List bytes;
@override
Widget build(BuildContext context) {
return new Scaffold(
body: new Container(child: Image.memory(bytes)),
floatingActionButton: FloatingActionButton(onPressed: () {
setState(() {
update();
});
}),
);
}
@override
void initState() {
super.initState();
update();
}
void update() {
setState(() {
bytes = Test.nextImage().getBytes();
});
}
}
class Test {
static img.Image image = new img.Image(200, 200, Colors.red.value);
static img.Image nextImage() {
var rng = new Random();
int w = rng.nextInt(image.width);
int h = rng.nextInt(image.height);
int c = rng.nextInt(256);
image.setPixel(w, h, c);
return image;
}
}
所以我想要一种有效的方式来查看图像以及实时处理图像的可能性