1 18 package org.apache.batik.ext.awt.image.rendered; 19 20 21 import java.awt.Rectangle ; 22 import java.awt.image.BufferedImage ; 23 import java.awt.image.Raster ; 24 import java.awt.image.WritableRaster ; 25 26 import org.apache.batik.ext.awt.image.GraphicsUtil; 27 35 public class BufferedImageCachableRed extends AbstractRed { 36 BufferedImage bi; 38 39 42 public BufferedImageCachableRed(BufferedImage bi) { 43 super((CachableRed)null, 44 new Rectangle (bi.getMinX(), bi.getMinY(), 45 bi.getWidth(), bi.getHeight()), 46 bi.getColorModel(), bi.getSampleModel(), 47 bi.getMinX(), bi.getMinY(), null); 48 49 this.bi = bi; 50 } 51 52 public BufferedImageCachableRed(BufferedImage bi, 53 int xloc, int yloc) { 54 super((CachableRed)null, new Rectangle (xloc, yloc, 55 bi.getWidth(), 56 bi.getHeight()), 57 bi.getColorModel(), bi.getSampleModel(), xloc, yloc, null); 58 59 this.bi = bi; 60 } 61 62 public Rectangle getBounds() { 63 return new Rectangle (getMinX(), 64 getMinY(), 65 getWidth(), 66 getHeight()); 67 } 68 69 72 public BufferedImage getBufferedImage() { 73 return bi; 74 } 75 76 public Object getProperty(String name) { 77 return bi.getProperty(name); 78 } 79 80 public String [] getPropertyNames() { 81 return bi.getPropertyNames(); 82 } 83 84 public Raster getTile(int tileX, int tileY) { 85 return bi.getTile(tileX,tileY); 86 } 87 88 public Raster getData() { 89 Raster r = bi.getData(); 90 return r.createTranslatedChild(getMinX(), getMinY()); 91 } 92 93 public Raster getData(Rectangle rect) { 94 Rectangle r = (Rectangle )rect.clone(); 95 96 if (r.intersects(getBounds()) == false) 97 return null; 98 r = r.intersection(getBounds()); 99 r.translate(-getMinX(), - getMinY()); 100 101 Raster ret = bi.getData(r); 102 return ret.createTranslatedChild(ret.getMinX()+getMinX(), 103 ret.getMinY()+getMinY()); 104 } 105 106 public WritableRaster copyData(WritableRaster wr) { 107 WritableRaster wr2 = wr.createWritableTranslatedChild 108 (wr.getMinX()-getMinX(), 109 wr.getMinY()-getMinY()); 110 111 GraphicsUtil.copyData(bi.getRaster(), wr2); 112 113 121 132 return wr; 133 } 134 } 135 | Popular Tags |