Reputation: 2063
I'm writing a face detect app and I want to crop the face that have detected on screen with the bounding box of that face.
I have searched all the way but only can crop with width height and aspect ratio.
I don't want to crop manual like other image crop plugin because they also crop with width height and aspect ratio as well.
Upvotes: 4
Views: 8880
Reputation: 2143
You can use https://github.com/brendan-duncan/image for that.
For your case, try to use copyCrop
.
https://github.com/brendan-duncan/image/blob/master/lib/src/transform/copy_crop.dart
copy_crop.dart
import '../image.dart';
/// Returns a cropped copy of [src].
Image copyCrop(Image src, int x, int y, int w, int h) {
Image dst = Image(w, h, channels: src.channels, exif: src.exif,
iccp: src.iccProfile);
for (int yi = 0, sy = y; yi < h; ++yi, ++sy) {
for (int xi = 0, sx = x; xi < w; ++xi, ++sx) {
dst.setPixel(xi, yi, src.getPixel(sx, sy));
}
}
return dst;
}
Usage
var croppedImage = Image copyCrop(Image sampleImageSrc, int pointX, int pointY, int desiredWidth, int desiredHeight);
Upvotes: 4