Cropping an image using Java -
how crop images in java? have class image manipulation.
the main method run method:
public static void main(string[] args) { gameproject gp = new gameproject(); gp.run(); } public void run(){ s = new screen(); try { displaymode dm = s.findfirstcompatiblemode(modes); s.setfullscreen(dm); fonts f = new fonts(); //checks if fonts exsist, if not install them. images = new images(); try { i.draw("h:\\dropbox\\dropbox\\gameproject\\src\\resources\\brock.png", 200, 200); thread.sleep(50000); } catch (exception e) {} } { s.restorescreen(); } }
images class:
package handlers; import javax.swing.imageicon; import java.awt.*; /** * * @author steven */ public class images { /** * @param args command line arguments */ private screen s; public void draw(string name, int x, int y) { //draws image s = new screen(); graphics2d g = s.getgraphics(); draws(g, name, x, y, getwidth(name), getheight(name)); } public void drawa(string name, int x, int y){ //draws image, allows more advanced image manipulation s = new screen(); graphics2d g = s.getgraphics(); draws(g, name, x, y, getwidth(name), getheight(name)); } public void draws(graphics g, string name, int x, int y, int w, int h) { //draws , updates screen s = new screen(); g.drawimage(new imageicon(name).getimage(), x, y, w, h, null); s.update(); } public int getwidth(string name) { //gets image width return new imageicon(name).geticonwidth(); } public int getheight(string name) { //gets images height return new imageicon(name).geticonheight(); } }
appreciated.
you can use cropimagefilter
crop images. also, take @ java.awt.image package, have lot of image manipulation routines.
Comments
Post a Comment