Created
August 11, 2022 00:35
-
-
Save jonahwilliams/3ab1beed81ea25253527a80d91f6c004 to your computer and use it in GitHub Desktop.
GPU vs IO image
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Copyright 2013 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:ui' as ui; | |
| import 'dart:developer'; | |
| import 'package:http/http.dart' as http; | |
| import 'package:flutter/foundation.dart'; | |
| import 'package:flutter/material.dart'; | |
| import 'package:vector_graphics/vector_graphics.dart'; | |
| import 'package:vector_graphics_compiler/vector_graphics_compiler.dart'; | |
| import 'data.dart'; | |
| Future<List<ui.Image>> drawImage() async { | |
| var recorder = ui.PictureRecorder(); | |
| var canvas = ui.Canvas(recorder); | |
| canvas.drawRect(ui.Rect.fromLTWH(20, 20, 100, 100), | |
| ui.Paint()..color = ui.Color(0xFFFF6D00)); | |
| var picture = recorder.endRecording(); | |
| var ioImage = await picture.toImage(200, 200); | |
| var gpuImage = picture.toImageSync(200, 200); | |
| return [ioImage, gpuImage]; | |
| } | |
| void main() { | |
| runApp(MyApp()); | |
| } | |
| class MyApp extends StatefulWidget { | |
| State createState() => MyAppState(); | |
| } | |
| class MyAppState extends State { | |
| ui.Image? io; | |
| ui.Image? gpu; | |
| @override | |
| void initState() { | |
| super.initState(); | |
| drawImage().then((images) { | |
| setState(() { | |
| io = images[0]; | |
| gpu = images[1]; | |
| }); | |
| }); | |
| } | |
| @override | |
| Widget build(BuildContext context) { | |
| return MaterialApp( | |
| title: 'Vector Graphics Demo', | |
| theme: ThemeData( | |
| primarySwatch: Colors.blue, | |
| ), | |
| home: Scaffold( | |
| body: Column( | |
| children: [ | |
| Container(height: 200), | |
| if (io != null) RawImage(image: io!, width: 200, height: 200), | |
| Container(height: 1, color: Colors.green), | |
| if (gpu != null) RawImage(image: gpu!, width: 200, height: 200), | |
| ], | |
| )), | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment