最新消息: USBMI致力于为网友们分享Windows、安卓、IOS等主流手机系统相关的资讯以及评测、同时提供相关教程、应用、软件下载等服务。

Flutter转换png图片为jpg图片

维修 admin 48浏览 0评论

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图片

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);
}

与本文相关的文章

发布评论

评论列表 (0)

  1. 暂无评论