Created
September 2, 2012 17:46
-
-
Save madan712/3602189 to your computer and use it in GitHub Desktop.
Java - Simple image cropping example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ImageCropper.java */ | |
import java.awt.image.BufferedImage; | |
import java.io.File; | |
import java.io.IOException; | |
import javax.imageio.ImageIO; | |
public class ImageCropper { | |
public static void main(String[] args) { | |
try { | |
BufferedImage originalImgage = ImageIO.read(new File("C:/Test/pool.jpg")); | |
System.out.println("Original Image Dimension: "+originalImgage.getWidth()+"x"+originalImgage.getHeight()); | |
BufferedImage SubImgage = originalImgage.getSubimage(300, 150, 200, 200); | |
System.out.println("Cropped Image Dimension: "+SubImgage.getWidth()+"x"+SubImgage.getHeight()); | |
File outputfile = new File("C:/Test/croppedImage.jpg"); | |
ImageIO.write(SubImgage, "jpg", outputfile); | |
System.out.println("Image cropped successfully: "+outputfile.getPath()); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Error: Could not create the Java Virtual Machine.
coming
Unrecognized option: --enable-preview
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
/home/webadmin/.cache/netbeans/12.2/executor-snippets/run.xml:111: The following error occurred while executing this line:
/home/webadmin/.cache/netbeans/12.2/executor-snippets/run.xml:94: Java returned: 1
BUILD FAILED (total time: 0 seconds)
Thanks very much this program what i need -- it allow u to position the part u want to crop then the size :)
is this working ??
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I don't know, why the size after resize is much smaller than the original size?
e.g.
1.4mb down to 77 kb
Could you explain it to me? (bow)