当我们处理相机时flutter, 我们用Camera plugin.
It has .startImageStream
返回的方法CameraImage cameraImage
数据类型。
In iOS, cameraImage.format
is bgra8888.
适用于安卓cameraImage.format
is yuv420.
在将这些格式编码为 JPEG 或 PNG 之前,我们需要一些字节操作并将每个字节放入图像缓冲区,然后在JpegEncoder
.
对于安卓系统来说,cameraImage(yuv420) to List<int>
本期讨论并实施:https://github.com/flutter/flutter/issues/26348#issuecomment-462321428 https://github.com/flutter/flutter/issues/26348#issuecomment-462321428
问题是,我们如何构建flutter图片(jpeg|png) from bgra8888 cameraImage
?
看看pub.dev
图像库API位于https://pub.dev/packages/image 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));
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)