Flutter转换png图片为jpg图片

编程入门 行业动态 更新时间:2024-10-22 11:37:29

Flutter转换png<a href=https://www.elefans.com/category/jswz/34/1770705.html style=图片为jpg图片"/>

Flutter转换png图片为jpg图片

1.需求

在xxx产品需求中,需要将png图片转为jpg图片。

2.引用库

 image: ^4.1.3

Dart图像库提供了以各种图像文件格式加载、保存和操作图像的功能。

该库可以与dart:io和dart:html一起用于命令行、Flutter和web应用程序。

注:4.0是该库先前版本的主要修订版。

支持的图像格式

Read/Write

  • JPG
  • PNG / Animated APNG
  • GIF / Animated GIF
  • BMP
  • TIFF
  • TGA
  • PVR
  • ICO

Read Only

  • WebP / Animated WebP
  • PSD
  • EXR

Write Only

  • CUR

3.代码实现

import 'package:image/image.dart' as imglib;//原图片本地路径 
final cmd = imglib.Command()..decodeImageFile(‘/xxx/xxx/xx.png’);//image对象
var image = await cmd.getImage();//转为jpg
var newImg = imglib.encodeJpg(image);
if (newPath != null) {File(‘/xxx/xxx/xx/new.jpg’).writeAsBytesSync(newImg);
}

更多推荐

Flutter转换png图片为jpg图片

本文发布于:2023-11-16 01:37:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1611132.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图片   Flutter   png   jpg

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!