Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. import 'dart:typed_data';
  2. import 'package:flutter/material.dart';
  3. import 'dart:ui' as ui;
  4.  
  5. void main() async {
  6. const double width = 800;
  7. const double height = 600;
  8. final ui.PictureRecorder recorder = new ui.PictureRecorder();
  9. final ui.Canvas canvas =
  10. new ui.Canvas(recorder, Rect.fromLTWH(0, 0, width, height));
  11.  
  12. canvas.drawRect(
  13. Rect.fromLTWH(0, 0, width, height),
  14. Paint()
  15. ..style = PaintingStyle.fill
  16. ..color = ui.Color.fromRGBO(128, 0, 0, 1.0)
  17. ..isAntiAlias = false);
  18. final ui.Picture picture = recorder.endRecording();
  19. ui.Image image = await picture.toImage(width.floor(), height.floor());
  20. ByteData data = await image.toByteData();
  21.  
  22. // Should be 128 as specified in our Paint fill.
  23. print("First pixel's R: ${data.getUint8(0)}");
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement