【问题标题】:How draw a rectangle directly on an image in flutter如何在颤动中直接在图像上绘制矩形
【发布时间】:2022-10-26 02:41:38
【问题描述】:

我想在实际图像上绘制一个矩形,并且不想使用颤振渲染器在顶层添加一个矩形作为视图。我可以获得像素颜色,但是如何覆盖像素呢?

    ByteData byteData = await rootBundle.load('assets/images/maps/map.jpg');
    Uint8List bytes = byteData.buffer.asUint8List();
    List<int> values = bytes;
    img.Image photo = img.decodeImage(values)!;
    final pixels = photo.getBytes(format: img.Format.rgba);

【问题讨论】:

    标签: flutter image dart pixel drawimage


    【解决方案1】:

    我不太确定,如果这是您需要的答案,那么使用堆栈呢?

    Stack(children: [
             image,
             Positioned.fill(
                child: CustomPaint(
                        painter: Sky(r), 
                        child: Container()));
                        }),
                    ],
    )
    ...
    
    
    class Sky extends CustomPainter {
      Rect rect;
    
      Sky(this.rect);
    
      @override
      void paint(Canvas canvas, Size size) {
        canvas.drawRect(rect, Paint()..color = Colors.black);
      }
    
      @override
      bool shouldRepaint(Sky oldDelegate) => false;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-09-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多