resize method
Resizes this image to the given newSize
.
Keep in mind that is considered an expensive operation and should be avoided in the game loop methods. Prefer using it in the loading phase of the game or components.
Implementation
Future<Image> resize(Vector2 newSize) async {
final recorder = PictureRecorder();
Canvas(recorder).drawImageRect(
this,
getBoundingRect(),
newSize.toRect(),
_whitePaint,
);
final picture = recorder.endRecording();
final resizedImage = await picture.toImageSafe(
newSize.x.toInt(),
newSize.y.toInt(),
);
return resizedImage;
}