-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Closed
Labels
r: timeoutIssue is closed due to author not providing the requested details in timeIssue is closed due to author not providing the requested details in time
Description
I read this issue, but did not find what I need
☂️ Lightweight Flutter Engines #72009
Problem description
- When I use the enginegroup method, the toimage API of RepaintBoundary may not meet expectations. Please see the comparison and experimental code
- I think it may be related to FlutterEngine Group resource sharing. Although it can be solved by abandoning the surfaceview mode, I think it can be better
Development environment
code desc
- Project code https://github.com/flutter/samples/tree/master/add_to_app/multiple_flutters
- group Engine with RenderMode.surface will get Actual results
- group Engine with RenderMode.texture will get Expected results or Actual results
- new engine with not group will always get Expected results
- I just added a Wiget that provides the generateImage method to generate graphics data(Uint8List)
import 'dart:typed_data';
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
class MyEntryWiget extends StatefulWidget {
const MyEntryWiget({Key? key}) : super(key: key);
@override
_MyEntryWigetState createState() => _MyEntryWigetState();
}
class _MyEntryWigetState extends State<MyEntryWiget> {
late GlobalKey _globalKey;
@override
void initState() {
super.initState();
_globalKey = GlobalKey();
}
@override
Widget build(BuildContext context) {
return RepaintBoundary(
key: _globalKey,
child: Column(
children: [
Container(
width: 120,
height: 120,
child: Image.network(
"https://avatars.githubusercontent.com/u/30870216?v=4")),
Text(
"I like flutter",
style: TextStyle(color: Colors.red),
)
],
));
;
}
/// pass return data to any platform to show
Future<Uint8List?> captureImage(GlobalKey rootKey) async {
try {
RenderRepaintBoundary boundary =
rootKey.currentContext!.findRenderObject() as RenderRepaintBoundary;
var image = await boundary.toImage(pixelRatio: 3.0);
ByteData? byteData = await image.toByteData(format: ImageByteFormat.png);
Uint8List? pngBytes = byteData?.buffer.asUint8List();
return pngBytes;
} catch (e) {
print(e);
}
return null;
}
}
- For example, on Android, byte data can be converted into bitmap display
public Bitmap stringToBitmap(byte[] string) { Bitmap bitmap = null; try { byte[] bitmapArray = Base64.decode(string, Base64.DEFAULT); bitmap = BitmapFactory.decodeByteArray(bitmapArray, 0, bitmapArray.length); } catch (Exception e) { e.printStackTrace(); } return bitmap; findViewById<ImageView>(R.id.iv).setImageBitmap()
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
r: timeoutIssue is closed due to author not providing the requested details in timeIssue is closed due to author not providing the requested details in time


