0

hello any way to get user signature from image , I want to require to get user signature from image , so is there possible to do that your text

above mention issue is solve in python through Signature Extractor , but how can solve issue in flutter

Signature Extractor github link: https://github.com/ahmetozlu/signature_extractor

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36

1 Answers1

-1

import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:image_picker/image_picker.dart';
import 'package:flutter_image/flutter_image.dart' as img;
import 'package:path_provider/path_provider.dart';

class SignatureExtractor extends StatefulWidget {
  @override
  _SignatureExtractorState createState() => _SignatureExtractorState();
}

class _SignatureExtractorState extends State<SignatureExtractor> {
  File? _imageFile;

  Future<void> _getImageFromGallery() async {
    final pickedImage =
        await ImagePicker().getImage(source: ImageSource.gallery);
    if (pickedImage != null) {
      setState(() {
        _imageFile = File(pickedImage.path);
      });
    }
  }

  Future<void> _extractSignature() async {
    if (_imageFile == null) return;

    final signatureImage = await img.decodeImageFromList(
      await _imageFile!.readAsBytes(),
      colorSpace: ColorSpace.srgb,
    );

    // Perform image processing and signature extraction here
    // Apply techniques like thresholding, edge detection, contour detection, etc.

    // Once you have the signature image, you can save it to a file or use it as needed
    final appDir = await getApplicationDocumentsDirectory();
    final signaturePath = '${appDir.path}/signature.png';
    await signatureImage.saveTo(signaturePath);
    print('Signature extracted and saved to: $signaturePath');
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Signature Extractor'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            if (_imageFile != null)
              Image.file(_imageFile!, width: 200, height: 200),
            ElevatedButton(
              onPressed: _getImageFromGallery,
              child: Text('Select Image'),
            ),
            ElevatedButton(
              onPressed: _extractSignature,
              child: Text('Extract Signature'),
            ),
          ],
        ),
      ),
    );
  }
}

void main() {
  runApp(MaterialApp(
    home: SignatureExtractor(),
  ));
}
Hardas
  • 44
  • 3