Switch to full style
General Java code examples
Post a reply

crop image in java

Tue Nov 11, 2008 7:59 pm

crop image in java
Code:
import java.awt.*;
import javax.swing.*;
import java.awt.image.CropImageFilter;
import java.awt.image.FilteredImageSource;

public class CropImage extends JFrame {
  Image image;
  Insets insets;

  public CropImage() {
    super("Crop Image");
    ImageIcon icon = new ImageIcon("image4.jpg");
    image = icon.getImage();
    image = createImage(new FilteredImageSource(image.
       getSource(),new CropImageFilter(75, 70, 140, 150)));
  }
  public void paint(Graphics g) {
    super.paint(g);
    if (insets == null) {
      insets = getInsets();
    }
    g.drawImage(image, insets.left, insets.top, this);
  }
  public static void main(String args[]) {
    JFrame frame = new CropImage();
    frame.setSize(250, 250);
    frame.show();
  }
}



Attachments
cropImage.gif
output if cropping image
cropImage.gif (6.18 KiB) Viewed 23855 times

Re: crop image in java

Fri Nov 25, 2011 7:49 am

Please tell me about createImage() the super("Crop Image") class........

Re: crop image in java

Sun Nov 27, 2011 2:00 am

Using it to create a new image object from original image "image4.jpg" after apply the Crop filter on it.

Post a reply
  Related Posts  to : crop image in java
 crop image using JQuery     -  
 JavaCV crop image     -  
 how to compress Bmp image in java...     -  
 Clip of image in java     -  
 Image Scale in java     -  
 flip image in java     -  
 java image effects     -  
 image binarization in java     -  
 image processing in java     -  
 Image Noise Filter in Java     -  

Topic Tags

Java Image