Java Code Examples for processing.core.PImage#copy()

The following examples show how to use processing.core.PImage#copy() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ImageUtil.java    From haxademic with MIT License 6 votes vote down vote up
public static void cropFillCopyImage( PImage src, PImage dest, boolean cropFill ) {
	float containerW = dest.width;
	float containerH = dest.height;
	float imageW = src.width;
	float imageH = src.height;
	
	float ratioW = containerW / imageW;
	float ratioH = containerH / imageH;
	float shorterRatio = ratioW > ratioH ? ratioH : ratioW;
	float longerRatio = ratioW > ratioH ? ratioW : ratioH;
	float resizedW = cropFill ? (float)Math.ceil(imageW * longerRatio) : (float)Math.ceil(imageW * shorterRatio);
	float resizedH = cropFill ? (float)Math.ceil(imageH * longerRatio) : (float)Math.ceil(imageH * shorterRatio);
	float offsetX = (float)Math.ceil((containerW - resizedW) * 0.5f);
	float offsetY = (float)Math.ceil((containerH - resizedH) * 0.5f);
	
	dest.copy( src, 0, 0, (int) imageW, (int) imageH, (int) offsetX, (int) offsetY, (int) resizedW, (int) resizedH );
}
 
Example 2
Source File: ImageUtil.java    From haxademic with MIT License 6 votes vote down vote up
public static void cropFillCopyImage(PImage src, PImage dest, int destX, int destY, int destW, int destH, boolean cropFill) {
	int imageW = src.width;
	int imageH = src.height;
	float ratioW = (float) destW / imageW;
	float ratioH = (float) destH / imageH;
	if(cropFill) {
		float fillRatio = ratioW > ratioH ? ratioW : ratioH;
		int scaledDestW = P.round(destW / fillRatio);	// scale destination dimension to match source, so we can puLl the rect at the right scale
		int scaledDestH = P.round(destH / fillRatio);
		int srcX = cropFill ? P.round(imageW/2 - scaledDestW/2) : 0;
		int srcY = cropFill ? P.round(imageH/2 - scaledDestH/2) : 0;
		int srcW = cropFill ? P.round(scaledDestW) : 0;
		int srcH = cropFill ? P.round(scaledDestH) : 0;
		dest.copy(src, srcX, srcY, srcW, srcH, destX, destY, destW, destH);
	} else {
		float letterboxRatio = ratioW > ratioH ? ratioH : ratioW;
		int resizedW = P.ceil(imageW * letterboxRatio);
		int resizedH = P.ceil(imageH * letterboxRatio);
		int offsetX = P.ceil((destW - resizedW) * 0.5f);
		int offsetY = P.ceil((destH - resizedH) * 0.5f);
		dest.copy(src, 0, 0, imageW, imageH, destX + offsetX, destY + offsetY, resizedW, resizedH);
	}
}
 
Example 3
Source File: PaperScreen.java    From PapARt with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Unsafe do not use unless you are sure. This will be moved to a utility
 * class.
 */
public static PImage getImageFrom(PVector coord, PImage src, PImage dst, int radius) {
    int x = (int) coord.x;
    int y = (int) coord.y;

    dst.copy(src,
            x - radius / 2,
            y - radius / 2,
            radius,
            radius,
            0, 0,
            radius,
            radius);
    return dst;
}
 
Example 4
Source File: ImageUtil.java    From haxademic with MIT License 4 votes vote down vote up
public static PImage getScaledImage( PImage image, int newWidth, int newHeight ) {
	PImage scaled = new PImage( newWidth, newHeight );
	scaled.copy( image, 0, 0, image.width, image.height, 0, 0, newWidth, newHeight );
	return scaled;
}
 
Example 5
Source File: ImageUtil.java    From haxademic with MIT License 4 votes vote down vote up
public static void copyImage(PImage src, PImage dest) {
	dest.copy(src, 0, 0, src.width, src.height, 0, 0, dest.width, dest.height);
}
 
Example 6
Source File: ImageUtil.java    From haxademic with MIT License 4 votes vote down vote up
public static void copyImageFlipH(PImage src, PImage dest) {
	dest.copy(src, 0, 0, src.width, src.height, dest.width, 0, -dest.width, dest.height);
}
 
Example 7
Source File: ImageUtil.java    From haxademic with MIT License 4 votes vote down vote up
public static void flipH(PImage img) {
	img.copy(0, 0, img.width, img.height, img.width, 0, -img.width, img.height);
}
 
Example 8
Source File: ImageUtil.java    From haxademic with MIT License 4 votes vote down vote up
public static void flipV(PImage img) {
	img.copy(0, 0, img.width, img.height, 0, img.height, img.width, -img.height);
}