rxlabz / flutter_canvas_to_image

flutter example : canvas to png

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Solution unclear

harshkumarkhatri opened this issue · comments

Hey. I have gone through your code and I found it unclear.
Can you please update it such that others can have a better reference to it?

Using the new requirements, I came out with this code - maybe that's more clear for you:

final recorder = PictureRecorder();
final canvas = Canvas(
    recorder,
    Rect.fromPoints(const Offset(0.0, 0.0), const Offset(200.0, 200.0)));

final stroke = Paint()
  ..color = Colors.grey
  ..style = PaintingStyle.stroke;

canvas.drawRect(
    const Rect.fromLTWH(0.0, 0.0, 200.0, 200.0), stroke);

final paint = Paint()
  ..color = Colors.purple
  ..style = PaintingStyle.fill;

canvas.drawCircle(
    const Offset(
      200.0,
      200.0,
    ),
    20.0,
    paint);

final picture = recorder.endRecording();
final img = await picture.toImage(200, 200);
final pngBytes = await img.toByteData(format: ImageByteFormat.png);

Now it's much more clear. Thanks for the update.