With flutter_svg 2.0+ we've lost the .toPicture, and its size method. This poses a problem when upscaling images, as the scale is not good (upscaled images can be blurred/pixelated). The problem has been discussed here https://github.com/dnfield/flutter_svg/issues/858
To get around this, I had to do the following:
static Future<ImageInfo> _loadAsync(SvgImageKey key) async {
final String rawSvg = await _getSvgString(key);
final pictureInfo = await vg.loadPicture(
SvgStringLoader(rawSvg),
null,
clipViewbox: false,
);
final ui.PictureRecorder recorder = ui.PictureRecorder();
final ui.Canvas canvas = ui.Canvas(recorder);
canvas.scale(key.pixelWidth / pictureInfo.size.width, key.pixelHeight / pictureInfo.size.height);
canvas.drawPicture(pictureInfo.picture);
final ui.Picture scaledPicture = recorder.endRecording();
final image = await scaledPicture.toImage(key.pixelWidth, key.pixelHeight);
return ImageInfo(
image: image,
scale: 1.0,
);
}
I tried to manipulate all the other methods scale, size, ... without success, only this fix solved my problem.
Hi,
With flutter_svg 2.0+ we've lost the .toPicture, and its size method. This poses a problem when upscaling images, as the scale is not good (upscaled images can be blurred/pixelated). The problem has been discussed here https://github.com/dnfield/flutter_svg/issues/858
To get around this, I had to do the following:
I tried to manipulate all the other methods scale, size, ... without success, only this fix solved my problem.
Is there a better solution?