【问题标题】:How To Create A Filtered Image In Flutter如何在 Flutter 中创建过滤后的图像
【发布时间】:2020-11-28 00:54:05
【问题描述】:

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

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 ...
}

【问题讨论】:

    标签: android flutter image-processing dart image-editing


    【解决方案1】:

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

    【讨论】:

    • 哇,太好了。非常感谢
    • 很高兴你喜欢@marvinralph :) 你能接受这个答案吗?
    • 但我似乎无法弄清楚的一件事是如何将 blendMethod 设置为颤振 BlendMode
    猜你喜欢
    • 2013-11-08
    • 2023-02-21
    • 2019-10-01
    • 1970-01-01
    • 2020-02-12
    • 2018-05-01
    • 1970-01-01
    • 2014-08-21
    • 1970-01-01
    相关资源
    最近更新 更多