Crop Image
Posted on: October 14, 2008 at 12:00 AM
To crop an image, an image is defined inside the class folder. The class ImageIcon calls its method getImage() which returns the specified image.

Crop Image

     

This section shows you how the image get crops.

To crop an image, an image is defined inside the class folder. The class ImageIcon calls its method getImage() which returns the specified image. The Insets class shows the border of a container which specifies the space leave at each of its edges.

To produce image data for a filtration of the original image, we take an existing image and a filter object by using the class FilteredImageSource. To crop an image, we have used the CropImageFilter class which is extended by the ImageFilter class. 

Here is the code of CropImage.java

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(7570140150)));
  }
  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(250250);
  frame.show();
  }
}

Output will be displayed as:

Download Source Code

Related Tags for Crop Image:
cimageideclassmethodgeticonordersetsreturnfolderborderidaiseteavdefinecontainershowifiecalltocropeachldciwsshespaceitlspeimceedgeincalasmntsidsidetimagecaacecallsclesspecallageicomehowdefinedwhichsurnspfoldatpacoldislleassrdthshoavedgesfinmageonolo


More Tutorials from this section

Ask Questions?    Discuss: Crop Image   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.