Untitled
unknown
dart
a year ago
1.8 kB
8
Indexable
class ImageGenerator {
final void Function(Uint8List, String, String) onImageGenerated;
StrokePath strokePath;
PenTypes activePen;
String drawingId;
String segmentId;
ImageGenerator({required this.onImageGenerated, required this.strokePath, required this.activePen, required this.drawingId, required this.segmentId});
void genImage() async {
// ignore: deprecated_member_use
double devicePixelRatio = window.devicePixelRatio;
double scaleFactor = devicePixelRatio * 5;
final width = ((strokePath.getWidth() + strokePath.png_padding) * scaleFactor);
final height = ((strokePath.getHeight() + strokePath.png_padding) * scaleFactor);
final recorder = PictureRecorder();
final canvas = Canvas(
recorder,
Rect.fromPoints(
Offset.zero,
Offset(strokePath.getWidth() + strokePath.png_padding, strokePath.getHeight() + strokePath.png_padding) * scaleFactor
),
);
Path? linesPath = strokePath.linesPath;
Path? circlesPath = strokePath.circlesPath;
final paint = activePen.paint;
final Matrix4 matrix4 = Matrix4.identity()..scale(scaleFactor, scaleFactor);
Path sLinepath = linesPath.transform(matrix4.storage);
Path sCirclepath = circlesPath.transform(matrix4.storage);
canvas.drawPath(sLinepath, paint);
canvas.drawPath(sCirclepath, paint);
final picture = recorder.endRecording();
// These lines are the ones that make the app freeze!!!!! //
var img = await picture.toImage(width.ceil(), height.ceil());
final byteData = await img.toByteData(format: ImageByteFormat.png);
// These lines are the ones that make the app freeze!!!!! //
print("IMAGE READY!!!!");
onImageGenerated(byteData!.buffer.asUint8List(), drawingId, segmentId);
}
}Editor is loading...
Leave a Comment