Answers for "flutter capture image from camera or gallery crop show"

4

flutter capture image from camera

import 'package:image_picker/image_picker.dart';

final _imagePicker = ImagePicker();
 
var _pickedFile = await _imagePicker.getImage(source: ImageSource.camera);
File _imageFilePicked = File(_pickedFile.path);
Posted by: Guest on March-29-2021
0

flutter crop captured image

import 'dart:io';
import 'dart:math';
import 'package:flutter/rendering.dart';
import 'package:image/image.dart' as IMG;

class ImageProcessor {
  static Future cropSquare(String srcFilePath, String destFilePath, bool flip) async {
    var bytes = await File(srcFilePath).readAsBytes();
    IMG.Image src = IMG.decodeImage(bytes);

    var cropSize = min(src.width, src.height);
    int offsetX = (src.width - min(src.width, src.height)) ~/ 2;
    int offsetY = (src.height - min(src.width, src.height)) ~/ 2;

    IMG.Image destImage =
      IMG.copyCrop(src, offsetX, offsetY, cropSize, cropSize);

    if (flip) {
        destImage = IMG.flipVertical(destImage);
    }

    var jpg = IMG.encodeJpg(destImage);
    await File(destFilePath).writeAsBytes(jpg);
  }
}
Posted by: Guest on October-15-2021

Code answers related to "flutter capture image from camera or gallery crop show"

Code answers related to "Dart"

Browse Popular Code Answers by Language