4Q-s-r-o / signature

Flutter plugin that creates a canvas for writing down a signature
MIT License
252 stars 83 forks source link

Image resoultion for saving image . #30

Open ganeshchenniah opened 3 years ago

ganeshchenniah commented 3 years ago
  1. When the signature is drawn on canvas , resolution is good , when the right mark is clicked , the resolution of the png goes bad . 2. When stroke width is 5, i can see crack in signature
MartinHlavna commented 3 years ago

Looks like there is issue with Picture.toImage() rendering. I was not able to fix it at the moment.

This issue sugests accomodating device pixel ratio into calculation but that was not helping in our case.

cs-nuuk commented 2 years ago

If anyone is looking for a workaround. You can do something like this with the pixel ratio MartinHlavna mentioned to get a higher resolution.

import 'dart:ui' as ui;
class _SignaturePageState extends State<SignaturePage> {
  GlobalKey globalKey = GlobalKey();
RepaintBoundary(
    key: globalKey,
    child: Signature(
        controller: _controller,
        backgroundColor: Colors.white,
    ),
);
IconButton(
    icon: const Icon(Icons.check),
    color: Colors.blue,
    onPressed: () async {
        final RenderRepaintBoundary? boundary = globalKey.currentContext?.findRenderObject() as RenderRepaintBoundary?;
        ui.Image? image = await boundary?.toImage(pixelRatio: 3);
        ByteData? byteData = await image?.toByteData(format: ui.ImageByteFormat.png);
        Uint8List? pngBytes = byteData?.buffer.asUint8List();

        if (pngBytes != null) {
            await Navigator.of(context).push(
                MaterialPageRoute<void>(
                    builder: (BuildContext context) {
                        return Scaffold(
                            appBar: AppBar(),
                            body: Center(
                                child: Image.memory(pngBytes),
                            ),
                        );
                    },
                ),
            );
        }
    },
),
carlos00027 commented 2 years ago

how send http multipart request?