0

I am using the flutter_camera_overlay plugin to achieve a cropped image of the card, but it's returning the original image instead of cropped one.

Example on how should work:

Preview

Dani3le_
  • 1,257
  • 1
  • 13
  • 22

1 Answers1

0

As you didn't provided any example code you are trying i will show you an example of the usage of this plugin to get the cropped image. Maybe it will help you understand.

import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:flutter_camera_overlay/flutter_camera_overlay.dart';

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key}) : super(key: key);

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  Uint8List? _croppedImageBytes;

  void _onPicture(PictureData pictureData) async {
    final croppedImageBytes = await FlutterCameraOverlay.cropImage(
      pictureData.bytes!,
      pictureData.width!,
      pictureData.height!,
      left: 100,
      top: 100,
      width: 200,
      height: 200,
    );

    setState(() {
      _croppedImageBytes = croppedImageBytes;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Camera Overlay'),
      ),
      body: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.stretch,
        children: [
          Expanded(
            child: FlutterCameraOverlay(
              onPicture: _onPicture,
            ),
          ),
          if (_croppedImageBytes != null)
            Padding(
              padding: const EdgeInsets.all(16.0),
              child: Card(
                child: Image.memory(
                  _croppedImageBytes!,
                  fit: BoxFit.cover,
                ),
              ),
            ),
        ],
      ),
    );
  }
}
Jason Simard
  • 103
  • 5
  • 18