Presentation is loading. Please wait.

Presentation is loading. Please wait.

Java 2D Image Manipulation A Brief Overview Ziv Yaniv.

Similar presentations


Presentation on theme: "Java 2D Image Manipulation A Brief Overview Ziv Yaniv."— Presentation transcript:

1 Java 2D Image Manipulation A Brief Overview Ziv Yaniv

2 BufferedImage ColorModel – Translates from pixel data to (R,G,B,  ), [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 pixel’s color. [DataBufferByte, DataBufferInt, DataBufferShort, DataBufferUShort]

3 Loading an Image (java 2D) public BufferedImage loadImage(String fileName) { Image img = Toolkit.getDefaultToolkit().getImage(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.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_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 y=imgHeight/2 – halfEdgeSize; y< imgHeight/2 + halfEdgeSize; y++) { for(int x=imgWidth/2 – halfEdgeSize; y< 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.


Download ppt "Java 2D Image Manipulation A Brief Overview Ziv Yaniv."

Similar presentations


Ads by Google