Image Processing Test : Image « 2D Graphics GUI « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Class
8. Collections Data Structure
9. Data Type
10. Database SQL JDBC
11. Design Pattern
12. Development Class
13. EJB3
14. Email
15. Event
16. File Input Output
17. Game
18. Generics
19. GWT
20. Hibernate
21. I18N
22. J2EE
23. J2ME
24. JDK 6
25. JNDI LDAP
26. JPA
27. JSP
28. JSTL
29. Language Basics
30. Network Protocol
31. PDF RTF
32. Reflection
33. Regular Expressions
34. Scripting
35. Security
36. Servlets
37. Spring
38. Swing Components
39. Swing JFC
40. SWT JFace Eclipse
41. Threads
42. Tiny Application
43. Velocity
44. Web Services SOA
45. XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java » 2D Graphics GUI » ImageScreenshots 
Image Processing Test
Image Processing Test
     
/**
 @version 1.0 1999-09-12
 @author Cay Horstmann
 */

import java.awt.Container;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.MediaTracker;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.awt.image.BufferedImageOp;
import java.awt.image.ByteLookupTable;
import java.awt.image.ConvolveOp;
import java.awt.image.Kernel;
import java.awt.image.LookupOp;
import java.awt.image.RescaleOp;
import java.io.File;

import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;

public class ImageProcessingTest {
  public static void main(String[] args) {
    JFrame frame = new ImageProcessingFrame();
    frame.show();
  }
}

class ImageProcessingFrame extends JFrame implements ActionListener {
  public ImageProcessingFrame() {
    setTitle("ImageProcessingTest");
    setSize(300400);
    addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
        System.exit(0);
      }
    });

    Container contentPane = getContentPane();
    panel = new ImageProcessingPanel();
    contentPane.add(panel, "Center");

    JMenu fileMenu = new JMenu("File");
    openItem = new JMenuItem("Open");
    openItem.addActionListener(this);
    fileMenu.add(openItem);

    exitItem = new JMenuItem("Exit");
    exitItem.addActionListener(this);
    fileMenu.add(exitItem);

    JMenu editMenu = new JMenu("Edit");
    blurItem = new JMenuItem("Blur");
    blurItem.addActionListener(this);
    editMenu.add(blurItem);

    sharpenItem = new JMenuItem("Sharpen");
    sharpenItem.addActionListener(this);
    editMenu.add(sharpenItem);

    brightenItem = new JMenuItem("Brighten");
    brightenItem.addActionListener(this);
    editMenu.add(brightenItem);

    edgeDetectItem = new JMenuItem("Edge detect");
    edgeDetectItem.addActionListener(this);
    editMenu.add(edgeDetectItem);

    negativeItem = new JMenuItem("Negative");
    negativeItem.addActionListener(this);
    editMenu.add(negativeItem);

    rotateItem = new JMenuItem("Rotate");
    rotateItem.addActionListener(this);
    editMenu.add(rotateItem);

    JMenuBar menuBar = new JMenuBar();
    menuBar.add(fileMenu);
    menuBar.add(editMenu);
    setJMenuBar(menuBar);
  }

  public void actionPerformed(ActionEvent evt) {
    Object source = evt.getSource();
    if (source == openItem) {
      JFileChooser chooser = new JFileChooser();
      chooser.setCurrentDirectory(new File("."));

      chooser.setFileFilter(new javax.swing.filechooser.FileFilter() {
        public boolean accept(File f) {
          String name = f.getName().toLowerCase();
          return name.endsWith(".gif"|| name.endsWith(".jpg")
              || name.endsWith(".jpeg"|| f.isDirectory();
        }

        public String getDescription() {
          return "Image files";
        }
      });

      int r = chooser.showOpenDialog(this);
      if (r == JFileChooser.APPROVE_OPTION) {
        String name = chooser.getSelectedFile().getAbsolutePath();
        panel.loadImage(name);
      }
    else if (source == exitItem)
      System.exit(0);
    else if (source == blurItem)
      panel.blur();
    else if (source == sharpenItem)
      panel.sharpen();
    else if (source == brightenItem)
      panel.brighten();
    else if (source == edgeDetectItem)
      panel.edgeDetect();
    else if (source == negativeItem)
      panel.negative();
    else if (source == rotateItem)
      panel.rotate();
  }

  private ImageProcessingPanel panel;

  private JMenuItem openItem;

  private JMenuItem exitItem;

  private JMenuItem blurItem;

  private JMenuItem sharpenItem;

  private JMenuItem brightenItem;

  private JMenuItem edgeDetectItem;

  private JMenuItem negativeItem;

  private JMenuItem rotateItem;
}

class ImageProcessingPanel extends JPanel {
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    if (image != null)
      g.drawImage(image, 00null);
  }

  public void loadImage(String name) {
    Image loadedImage = Toolkit.getDefaultToolkit().getImage(name);
    MediaTracker tracker = new MediaTracker(this);
    tracker.addImage(loadedImage, 0);
    try {
      tracker.waitForID(0);
    catch (InterruptedException e) {
    }
    image = new BufferedImage(loadedImage.getWidth(null), loadedImage
        .getHeight(null), BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = image.createGraphics();
    g2.drawImage(loadedImage, 00null);

    repaint();
  }

  private void filter(BufferedImageOp op) {
    BufferedImage filteredImage = new BufferedImage(image.getWidth(), image
        .getHeight(), image.getType());
    op.filter(image, filteredImage);
    image = filteredImage;
    repaint();
  }

  private void convolve(float[] elements) {
    Kernel kernel = new Kernel(33, elements);
    ConvolveOp op = new ConvolveOp(kernel);
    filter(op);
  }

  public void blur() {
    float weight = 1.0f 9.0f;
    float[] elements = new float[9];
    for (int i = 0; i < 9; i++)
      elements[i= weight;
    convolve(elements);
  }

  public void sharpen() {
    float[] elements = 0.0f, -1.0f0.0f, -1.0f5.f, -1.0f0.0f, -1.0f,
        0.0f };
    convolve(elements);
  }

  void edgeDetect() {
    float[] elements = 0.0f, -1.0f0.0f, -1.0f4.f, -1.0f0.0f, -1.0f,
        0.0f };
    convolve(elements);
  }

  public void brighten() {
    float a = 1.5f;
    float b = -20.0f;
    RescaleOp op = new RescaleOp(a, b, null);
    filter(op);
  }

  void negative() {
    byte negative[] new byte[256];
    for (int i = 0; i < 256; i++)
      negative[i(byte) (255 - i);
    ByteLookupTable table = new ByteLookupTable(0, negative);
    LookupOp op = new LookupOp(table, null);
    filter(op);
  }

  void rotate() {
    AffineTransform transform = AffineTransform.getRotateInstance(Math
        .toRadians(5), image.getWidth() 2, image.getHeight() 2);
    AffineTransformOp op = new AffineTransformOp(transform,
        AffineTransformOp.TYPE_BILINEAR);
    filter(op);
  }

  private BufferedImage image;
}


           
         
    
    
    
    
  
Related examples in the same category
1. Image size Image size
2. Image demoImage demo
3. Getting the Color Model of an Image
4. Filtering the RGB Values in an Image
5. Create a filter that can modify any of the RGB pixel values in an image.
6. This filter removes all but the red values in an image
7. Load and draw image
8. Paint an IconPaint an Icon
9. Image Processing: Brightness and ContrastImage Processing: Brightness and Contrast
10. Image with mouse drag and move eventImage with mouse drag and move event
11. Image Animation and ThreadImage Animation and Thread
12. Image Color Gray EffectImage Color Gray Effect
13. Image BufferingImage Buffering
14. Image Effect: CombineImage Effect: Combine
15. AffineTransform demoAffineTransform demo
16. Image Effect: Rotate Image using DataBufferImage Effect: Rotate Image using DataBuffer
17. Image Effect: Sharpen, blurImage Effect: Sharpen, blur
18. Image scale
19. Image crop
20. Demonstrating the Drawing of an Image with a Convolve Operation
21. Demonstrating Use of the Image I/O Library
22. Adding Image-Dragging Behavior
23. Sending Image Objects through the ClipboardSending Image Objects through the Clipboard
24. Anti AliasAnti Alias
25. Image OperationsImage Operations
26. Image ViewerImage Viewer
27. Get the dimensions of the image; these will be non-negative
28. Standalone Image Viewer - works with any AWT-supported format
29. Toolkit.getImage() which works the same in either Applet or Application
30. Image Transfer TestImage Transfer Test
31. Double Buffered Image
32. Graband Fade: displays image and fades to black
33. Graband Fade with Rasters
34. Rotate Image 45 Degrees
35. Convert java.awt.image.BufferedImage to java.awt.Image
36. Filter image by multiplier its red, green and blue color
37. Drags within the imageDrags within the image
38. TYPE_INT_RGB and TYPE_INT_ARGB are typically used
39. Pixels from a buffered image can be modified
40. Calculation of the mean value of an image with Raster
41. Use PixelGrabber class to acquire pixel data from an Image object
42. Flip an image
43. Rendered Image
44. Image Panel
45. Image Utils
46. Returns an image resource.
47. Create Gradient Image
48. Create Gradient Mask
49. Create Translucent Image
50. Make Raster Writable
51. A frame that displays an image
52. Optimized version of copyData designed to work on Integer packed data with a SinglePixelPackedSampleModel
w___w_w._j___a___v__a_2__s___.__c__o_m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.