3

I'm drawing to a Canvas in Flutter using drawImageRect:

canvas.drawImageRect(image, sourceRect, destRect, _paint);

I have an Opacity value (a double between 0 and 1). How do I paint the image using this value (so that 0 is not visible and 0.5 is half-opacity)?

Danny Tuppeny
  • 40,147
  • 24
  • 151
  • 275

2 Answers2

5

Just set the color opacity

final _paint = Paint();
final opacity = 0.5;
_paint.color = Color.fromRGBO(0, 0, 0, opacity);
canvas.drawImageRect(image, sourceRect, destRect, _paint);
nicetry
  • 91
  • 1
  • 4
0

You can process the image before rendering using this library. Also I would suggest you to do all operations of this library using the isolates, using the compute() function of flutter would be easy as it blocks the whole UI.

Ryosuke
  • 3,592
  • 1
  • 11
  • 28