Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/rxlabz/flutter_canvas_to_image

flutter example : canvas to png
https://github.com/rxlabz/flutter_canvas_to_image

canvas flutter image

Last synced: about 1 month ago
JSON representation

flutter example : canvas to png

Awesome Lists containing this project

README

        

# canvas_to_image

a simple Flutter canvas to png file example

![screen](screenshot.png)

```dart
final recorder = new ui.PictureRecorder();
final canvas = new Canvas(
recorder,
new Rect.fromPoints(
new Offset(0.0, 0.0), new Offset(200.0, 200.0)));

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

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

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

canvas.drawCircle(
new Offset(
widget.rd.nextDouble() * 200.0,
widget.rd.nextDouble() * 200.0,
),
20.0,
paint);

final picture = recorder.endRecording();
final img = picture.toImage(200, 200);
final pngBytes = await img.toByteData(format: new ui.EncodingFormat.png());
```

In this example the image is displayed in a Image.memory widget

```dart
new Image.memory(new Uint8List.view(imgBytes.buffer));
```

___

## Getting Started with Flutter

For help getting started with Flutter, view our online
[documentation](https://flutter.io/).