Flutter CustomPainter paintImage lose quality after save

36 Views Asked by At

When I want to save the painted picture painted picture loses that significantly then quality. Here is my Code so save:

ui.PictureRecorder recorder = ui.PictureRecorder();
    Canvas canvas = Canvas(recorder);
    MyPainter painter =
        MyPainter (backgroundImage!, shapes, repaint, setCancasSize);
    painter.paint(canvas, cancasSize);

    print('canvas save size ${cancasSize.width}:${cancasSize.height}');
    print(
        'backgroundImage save size ${backgroundImage!.width}:${backgroundImage!.height}');

    ui.Image renderedImage = await recorder
        .endRecording()
        .toImage(cancasSize.width.floor(), cancasSize.height.floor());

    var pngBytes =
        await renderedImage.toByteData(format: ui.ImageByteFormat.png);

    File saveFile = File(backgroundImagePath);

    if (!saveFile.existsSync()) {
      saveFile.createSync(recursive: true);
    }
    saveFile.writeAsBytesSync(pngBytes!.buffer.asUint8List(), flush: true);
0

There are 0 best solutions below