在Flutter iOS中将jpg图像转换为png图像 [英] Convert jpg image to png image in Flutter iOS
本文介绍了在Flutter iOS中将jpg图像转换为png图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在颤动中将照片库中选择的jpg图像转换为png图像?
How can I convert a jpg image selected from photo gallery to png image in flutter?
推荐答案
看看图像包.以下是示例部分中提供的代码段,它将JPEG
转换为PNG
:
Take a look at the image package. The following is a snippet available in the examples section, which converts JPEG
to PNG
:
import 'dart:io';
import 'package:image/image.dart';
void main() {
// Read a jpeg image from file.
Image image = decodeImage(new File('test.jpg').readAsBytesSync());
// Resize the image to a 120x? thumbnail (maintaining the aspect ratio).
Image thumbnail = copyResize(image, 120);
// Save the thumbnail as a PNG.
new File('out/thumbnail-test.png')
..writeAsBytesSync(encodePng(thumbnail));
}
这篇关于在Flutter iOS中将jpg图像转换为png图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文