Flutter-如何在自定义绘画中调整图像的高度和宽度?

时间:2018-06-25 10:35:52

标签: dart flutter

在这里,我将图像列表传递给ImagePaint类,以循环方式剪切图像,如果可以减小图像的高度和宽度,则可以剪切图像,但仅剪切图像的一部分。然后它将适合您的圈子,如果有想法请发表评论。

COMMAND: username@host.host used IDENTIFY and failed to identify to nonexistent account username

以循环方式打印此图像: this image is printed in a circular manner

这是我正在剪切图像并循环打印的应用程序: This is my app I am clipping image and printing in circular

1 个答案:

答案 0 :(得分:1)

我只是想出了如何缩小图像并将其发送给画家进行绘制的方法。

缩小图像并将其返回的方法发送到绘图类。

如果它对您有用,请多谢我的赞许,谢谢。

import 'dart:ui' as ui;
import 'package:image/image.dart' as IMG;

Future<ui.Image> loadImage( List<int> data ) async {
   final IMG.Image image = IMG.decodeImage(data);
   final IMG.Image resized = IMG.copyResize(image, width: 200);
   final List<int> resizedBytes = IMG.encodePng(resized);
   final Completer<ui.Image> completer = new Completer();

   ui.decodeImageFromList(resizedBytes, (ui.Image img) => completer.complete(img));
   return completer.future;
}

绘画课。

class CustomDraw extends CustomPainter {
  final ui.Image image;

   const CustomDraw({this.image});

  @override
  void paint(Canvas canvas, Size size) {
    Paint paint = new Paint();
    canvas.drawImage(image, new Offset(40.0, 10.0), paint);
  }

   @override
   bool shouldRepaint(CustomPainter oldDelegate) {
     return false;
   }
}