Java 2D Image Manipulation A Brief Overview - PowerPoint PPT Presentation

About This Presentation
Title:

Java 2D Image Manipulation A Brief Overview

Description:

are translated to pixel data are then using the ColorModel to the ... { Image img = Toolkit.getDefaultToolkit().getImage(fileName); MediaTracker tracker = new ... – PowerPoint PPT presentation

Number of Views:38
Avg rating:3.0/5.0
Slides: 6
Provided by: zivy4
Category:

less

Transcript and Presenter's Notes

Title: Java 2D Image Manipulation A Brief Overview


1
Java 2D Image ManipulationA Brief Overview
Ziv Yaniv
2
BufferedImage
  • ColorModel Translates from pixel data to
    (R,G,B,a), ComponentColorModel,

  • IndexColorModel, PackedColorModel .
  • Raster The image data. Use the raster to access
    specific pixels or change their
  • value (WritableRaster).
  • SampleModel How to translate the data found in
    the DataBuffer as pixel
  • values.
    ComponentSampleModel, MultiPixelPackedSampleModel
    ,

  • SinglePixelPackedSampleModel
  • DataBuffer The actual image values which with
    the help of the SampleModel
  • are translated to
    pixel data are then using the ColorModel to the
  • pixels color.
    DataBufferByte, DataBufferInt, DataBufferShort,
  • DataBufferUShort

3
Loading an Image (java 2D)
  • public BufferedImage loadImage(String fileName)
  • Image img Toolkit.getDefaultToolkit().getIma
    ge(fileName)
  • MediaTracker tracker new MediaTracker(new
    Component() )
  • tracker.addImage(img, 0)
  • try
  • tracker.waitForID(0)
  • catch(InterruptedException e) //error
    while loading
  • BufferedImage res new BufferedImage(img.getW
    idth(null),

  • img.getHeight(null),
  • BufferedImage.TYPE_I
    NT_RGB)
  • Graphics2D g res.createGraphics()
  • g.drawImage(img, null, null)
  • return res

4
Setting Pixel Values
//draw a red square in the middle of an
image final int halfEdgeSize 5 int redPixel
255, 0, 0 BufferedImage image
loadImage(theFileName) //pixel type is
INT_RGB WritableRaster raster
image.getRaster() int imgWidth
image.getWidth() int imgHeight
image.getHeight() for(int yimgHeight/2
halfEdgeSize ylt imgHeight/2 halfEdgeSize y)
for(int ximgWidth/2 halfEdgeSize ylt
imgWidth/2 halfEdgeSize x)
raster.setPixe(x, y, redPixel)
5
BufferedImageOp
  • Operations/Filters on BufferedImage objects are
    classes which implement the
  • BufferedImageOp interface.
  • Note These filters are single source single
    destination filters.
  • For more advanced filters see Java
    Advanced Imaging JAI package.
  • The available filters in the java 2D package
    are
  • LookupOp, ConvolveOp, AffineTransformOp,
    ColorConvertOp, RescaleOp
  • For examples of using these filters see the
    java tutorial.
Write a Comment
User Comments (0)
About PowerShow.com