我正在尝试创建图像滤镜,我想知道的是,是否可以将滤色镜应用于图像,然后在应用了滤色镜的情况下保存该图像?如果是,那么如何。现在,我已经可以使用以下代码将滤色器应用于图像。但是,需要保存该图像,并使其与彩色滤光片一起显示。
Container(
child: Stack(
children: <Widget>[
ColorFiltered(
colorFilter: ColorFilter.mode(Colors.black87, BlendMode.color),
child: Image(
image: FileImage(
this.images[index]
),
),
),
)
]
)
);
所需要的是某种类似的功能,它将原始图像转换为应用了滤色器的图像。void transformImage(String path) {
// do something here ...
}
最佳答案
使用Image小部件,您可以进行各种操作。
import 'dart:io';
import 'package:image/image.dart';
void main() {
// Create an image
Image image = Image(320, 240); // You can also load an image here
// Fill it with a solid color (blue) OR add color filter
fill(image, getColor(0, 0, 255));
// Draw some text using 24pt arial font
drawString(image, arial_24, 0, 0, 'Hello World');
// Draw a line
drawLine(image, 0, 0, 320, 240, getColor(255, 0, 0), thickness: 3);
// Blur the image
gaussianBlur(image, 10);
// Save the image to disk as a PNG
File('test.png').writeAsBytesSync(encodePng(image));
}