Search
 
SCRIPT & CODE EXAMPLE
 

DART

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);
  }
}
Comment

PREVIOUS NEXT
Code Example
Dart :: how can i deep copy in dart 
Dart :: add a button that changes the text in flutter 
Dart :: english_words.dart 
Dart :: list join dart 
Dart :: string null dart 
Dart :: change color icon tabbar flutter 
Dart :: dart fixed length list 
Dart :: empty object in dart 
Dart :: flutter concat string list 
Dart :: comments in dart 
Dart :: install fvm in flutter using pub package 
Dart :: dart how to tell if an object is an instance of a class 
Dart :: flutter remove item from list 
Dart :: create extention in dart 
Dart :: how to iterate object in dart 
Dart :: flutter standarrt icon size 
Dart :: flutter run future builder only 1 time 
Dart :: dart get href attribute 
Dart :: dart add list to list 
Swift :: format decimal place swift 
Swift :: swift append element to array 
Swift :: delete padding list swiftui 
Swift :: swift collection view cell size 
Swift :: swift uiswitch change size 
Swift :: swift access appdelegate from viewcontroller 
Swift :: swift remove all duplicates from an array 
Swift :: post API Call in swift 
Swift :: swift change background color 
Swift :: closure swift 
Swift :: remove cocoapods swiftr 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =