颤振:将文件(图像)裁剪为一个圆圈 [英] Flutter: crop File (image) as a circle

查看:69
本文介绍了颤振:将文件(图像)裁剪为一个圆圈的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试裁剪文件(图像文件)。
这就是我所拥有的:





这就是我想要裁剪后得到的东西(带有圆形裁剪的png)





重要的是文件应为png,因此它没有白色边框。



是否有支持此功能的软件包?



预先感谢!

解决方案

这些简单的步骤即可获得所需的结果。 / p>

创建 PictureRecorder



使用 PictureRecorder创建画布



使用 canvas.drawCircle()在画布上绘制圆。



在Pictur上调用 endRecording() eRecorder来获取图片。



在图片上调用 toImage()



将图像转换为ByteData()



使用getApplicationDocumentsDirectory()在本地保存图像,仅当您要保存时



带有源代码的完整答案


I'm trying to crop a File (imagefile) in flutter. This is what I have:

This is what I would like to get after crop (a png with circle crop)

It's important that the file is png, so it doesn't have white borders.

Is there a package that support this?

Thanks in advance!

解决方案

These simple steps get the required result.

Create a PictureRecorder.

Create a Canvas with your PictureRecorder.

Draw circle in canvas using canvas.drawCircle().

Call endRecording() on the PictureRecorder to get a Picture.

Call toImage() on the Picture.

Convert image toByteData() .

Save image locally using getApplicationDocumentsDirectory() ,only if you want to save.

FULL ANSWER with SOURCE CODE

这篇关于颤振:将文件(图像)裁剪为一个圆圈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆