Alm*_*bek 7 camera image-processing dart flutter
当我们在flutter中处理相机时,我们使用Camera插件。
它有.startImageStream返回CameraImage cameraImage数据类型的方法。
在 iOS 中,cameraImage.format是bgra8888。
对于 AndroidcameraImage.format是yuv420。
在将这些格式编码为 JPEG 或 PNG 之前,我们需要一些字节操作并将每个字节放入图像缓冲区,然后在JpegEncoder.
对于android,cameraImage(yuv420) to List<int>本期讨论并实现:https://github.com/flutter/flutter/issues/26348#issuecomment-462321428
问题是,我们如何从bgra8888构造 flutter Image(jpeg|png)? cameraImage
查看pub.dev图像库 API,网址为https://pub.dev/packages/image。它可以从任何图像格式进行转换,无论是 bgra8888 还是 yuv420。此示例将其转换为 PNG 文件:
import 'dart:io';
import 'package:image/image.dart';
void main() {
// Read an image from file
// decodeImage will identify the format of the image and use the appropriate
// decoder.
Image image = decodeImage(File('test.bgra8888').readAsBytesSync());
// Resize the image to a 120x? thumbnail (maintaining the aspect ratio).
Image thumbnail = copyResize(image, width: 120);
// Save the thumbnail as a PNG.
File('thumbnail.png').writeAsBytesSync(encodePng(thumbnail));
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8857 次 |
| 最近记录: |