gpt4 book ai didi

image-processing - 如何在 iOS 的 flutter 中将图像流缓冲区转换为 jpeg 图像字节?

转载 作者:IT王子 更新时间:2023-10-29 06:55:52 32 4
gpt4 key购买 nike

当我们在flutter中处理相机时,我们使用Camera插件。
它有 .startImageStream返回 CameraImage cameraImage 的方法数据类型。

在 iOS 中,cameraImage.formatbgra8888
对于安卓cameraImage.formatyuv420

在将这些格式编码为 JPEG 或 PNG 之前,我们需要进行一些字节操作并将每个字节放入图像缓冲区,然后在 JpegEncoder 中使用。 .

对于安卓,cameraImage(yuv420) to List<int>本期讨论实现:https://github.com/flutter/flutter/issues/26348#issuecomment-462321428

问题是,我们如何从 bgra8888 cameraImage 构建 flutter Image(jpeg|png)

最佳答案

https://pub.dev/packages/image 查看 pub.dev 图像库 API .它可以从任何图像格式进行转换,无论是 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));
}

关于image-processing - 如何在 iOS 的 flutter 中将图像流缓冲区转换为 jpeg 图像字节?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57478522/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com