Skip to content

Instantly share code, notes, and snippets.

@jonahwilliams
Created March 24, 2024 20:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonahwilliams/2a08ec205bbbfc52723101663c529357 to your computer and use it in GitHub Desktop.
Save jonahwilliams/2a08ec205bbbfc52723101663c529357 to your computer and use it in GitHub Desktop.
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'dart:io';
import 'dart:typed_data';
import 'dart:ui' as ui;
import 'package:flutter/material.dart';
const double z = 1000000000; // 1e9
void main() async {
final ui.PictureRecorder recorder = ui.PictureRecorder();
final Canvas canvas = Canvas(recorder);
canvas.drawCircle(const Offset(12.0, 12.0), 10.0, Paint()..color = const Color(0xFFFF0000)); // should be obscured
canvas.drawRect(const Rect.fromLTRB(-z, -z, z/7, z/3), Paint()..color = const Color(0xFF009900)); // should cover everything
final ui.Picture picture = recorder.endRecording();
var bytes = await picture.toImageSync(100, 100). toByteData(format: ui.ImageByteFormat.png);
// runApp(MaterialApp(
// home: Scaffold(
// body: Center(
// child: CustomPaint(painter: FooPainter(), size: Size(500, 500))
// )
// )
// ));
runApp(MaterialApp(
home: Scaffold(
body: Center(
child: Image.memory(bytes!.buffer.asUint8List()),
)
)
));
}
// class FooPainter extends CustomPainter {
// @override
// void paint(ui.Canvas canvas, ui.Size size) {
// final ui.Image image;
// {
// final ui.PictureRecorder recorder = ui.PictureRecorder();
// final Canvas canvas = Canvas(recorder);
// canvas.drawCircle(const Offset(12.0, 12.0), 10.0, Paint()..color = const Color(0xFFFF0000)); // should be obscured
// canvas.drawRect(const Rect.fromLTRB(-z, -z, z/7, z/3), Paint()..color = const Color(0xFF009900)); // should cover everything
// final ui.Picture picture = recorder.endRecording();
// image = picture.toImageSync(100, 100);
// }
// canvas.drawImage(image, Offset.zero, Paint());
// }
// @override
// bool shouldRepaint(covariant CustomPainter oldDelegate) {
// return true;
// }
// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment