title: How can I apply matrix filter to canvas?
body: <p>I am developing an image editor using the Flutter framework and Dart and I can't apply matrix filter to canvas.</p>
  
  <p>I'm trying to apply a matrix filter to the canvas using a "Paint" class and "canvas.drawPaint(paint)" function, but I get black canvas.</p>
  
  <p><a href="https://i.stack.imgur.com/wrP8b.png" rel="nofollow noreferrer">Original image</a></p>
  
  <p><a href="https://i.stack.imgur.com/OaEiE.png" rel="nofollow noreferrer">Expected (Variant 2 in code)</a></p>
  
  <p><a href="https://i.stack.imgur.com/FbolG.png" rel="nofollow noreferrer">I get</a></p>
  
  <pre><code>class EditorPainter extends CustomPainter {
  
    final ui.Image image;
    final double zoom;
    final Offset offset;
  
    EditorPainter({
      @required this.image,
      @required this.zoom,
      @required this.offset,
      this.elements
    });
  
    @override
    void paint(Canvas canvas, Size size) {
      Size imageSize = Size(image.width.toDouble(), image.height.toDouble());
      Size targetSize = imageSize * zoom;
  
      // Variant 1 - not working (draws black canvas)
  
      paintImage(
        canvas: canvas,
        rect: offset &amp; targetSize,
        image: image,
        fit: BoxFit.fill
      );
  
  
      // Paint with "sepia" filter
      final Paint paint = Paint()
        ..colorFilter = ColorFilter.matrix([
          0.393, 0.768, 0.189, 0.0, 0.0,
          0.349, 0.686, 0.168, 0.0, 0.0,
          0.272, 0.534, 0.131, 0.0, 0.0,
          0.0, 0.0, 0.0, 1.0, 0.0,
        ]);
  
      canvas.drawPaint(paint);
  
      // Variant 2 - working 
      // Image with "sepia" filter
      paintImage(
        canvas: canvas,
        rect: offset &amp; targetSize,
        image: image,
        fit: BoxFit.fill,
        colorFilter: ColorFilter.matrix([
          0.393, 0.768, 0.189, 0.0, 0.0,
          0.349, 0.686, 0.168, 0.0, 0.0,
          0.272, 0.534, 0.131, 0.0, 0.0,
          0.0, 0.0, 0.0, 1.0, 0.0,
        ])
      );
    }
  }
  </code></pre>
  
  <p>I expect to get a canvas with a filtered image, but I get a black canvas.
  I tried to assign BlendMode to the Paint, but it did not help.</p>