/** * Same as {@link #subimage(int, int, int, int, ImageBase)}, but sets the storage for the input subimage * to null. * * @param x0 x-coordinate of top-left corner of the sub-image, inclusive. * @param y0 y-coordinate of top-left corner of the sub-image, inclusive. * @param x1 x-coordinate of bottom-right corner of the sub-image, exclusive. * @param y1 y-coordinate of bottom-right corner of the sub-image, exclusive. * @return A sub-image of 'this' image. */ public T subimage(int x0, int y0, int x1, int y1 ) { return subimage(x0,y0,x1,y1,null); }
/** * Clip the input image to ensure a constant aspect ratio */ T clipInput(T input, T output) { double ratioInput = input.width/(double)input.height; double ratioOutput = output.width/(double)output.height; T a = input; if( ratioInput > ratioOutput ) { // clip the width int width = input.height*output.width/output.height; int x0 = (input.width-width)/2; int x1 = x0 + width; clipped = input.subimage(x0,0,x1,input.height, clipped); a = clipped; } else if( ratioInput < ratioOutput ) { // clip the height int height = input.width*output.height/output.width; int y0 = (input.height-height)/2; int y1 = y0 + height; clipped = input.subimage(0,y0,input.width,y1, clipped); a = clipped; } return a; } }
subImg[i] = larger[i].subimage(5, 6, 5 + img.getWidth(), 6 + img.getHeight(), null); subImg[i].setTo(img);