android - 如何在 Flutter 中创建过滤图像

标签 android flutter image-processing dart image-editing

我正在尝试创建一个图像滤镜,我想知道的是,是否可以对图像应用滤色器,然后保存应用了滤色器的图像?如果是那么如何。现在我已经能够使用以下代码将滤色器应用于图像。但我们需要的是保存该图像并让它与滤色器一起显示。

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

关于android - 如何在 Flutter 中创建过滤图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63305968/

相关文章:

android - 知道 API 是由我们的应用程序还是第三方应用程序调用的?

Flutter:能知道你现在是否在舞台下吗?

c# - 使用 System.Windows.Media.Imaging 合成两个位图

python - 如何将年龄和性别数据添加到卷积神经网络的图像中?

android - Seekbar 进度可绘制不显示和 API 23

android - 如何更改 DialogFragment 大小

android - 来自辅助类的sharedPreference

flutter - 如何对包含括号的字符串使用拆分方法?

flutter - Flutter 尽快迁移的最佳 Firebase 替代方案是什么?

c# - C#中位图图像的灰度变暗问题