copyCrop function

Image copyCrop (
  1. Image src,
  2. int x,
  3. int y,
  4. int w,
  5. int h
)

Returns a cropped copy of src.

Implementation

Image copyCrop(Image src, int x, int y, int w, int h) {
  var dst =
      Image(w, h, channels: src.channels, exif: src.exif, iccp: src.iccProfile);

  for (var yi = 0, sy = y; yi < h; ++yi, ++sy) {
    for (var xi = 0, sx = x; xi < w; ++xi, ++sx) {
      dst.setPixel(xi, yi, src.getPixel(sx, sy));
    }
  }

  return dst;
}