📄 bufferedimage.java
字号:
return 0; } public int getNumXTiles() { return 1; } public int getNumYTiles() { return 1; } public Object getProperty(String string) { if (properties == null) return null; return properties.get(string); } public Object getProperty(String string, ImageObserver imageobserver) { return getProperty(string); } public String[] getPropertyNames() { // FIXME: implement return null; } public int getRGB(int x, int y) { Object rgbElem = raster.getDataElements(x, y, null // create as needed ); return colorModel.getRGB(rgbElem); } public int[] getRGB(int startX, int startY, int w, int h, int[] rgbArray, int offset, int scanlineStride) { if (rgbArray == null) { /* 000000000000000000 00000[#######----- [ = start -----########----- ] = end -----#######]00000 000000000000000000 */ int size = (h-1)*scanlineStride + w; rgbArray = new int[size]; } int endX = startX + w; int endY = startY + h; /* *TODO*: Opportunity for optimization by examining color models... Perhaps wrap the rgbArray up in a WritableRaster with packed sRGB color model and perform optimized rendering into the array. */ Object rgbElem = null; for (int y=startY; y<endY; y++) { int xoffset = offset; for (int x=startX; x<endX; x++) { int rgb; rgbElem = raster.getDataElements(x, y, rgbElem); rgb = colorModel.getRGB(rgbElem); rgbArray[xoffset++] = rgb; } offset += scanlineStride; } return rgbArray; } public WritableRaster getRaster() { return raster; } public SampleModel getSampleModel() { return raster.getSampleModel(); } public ImageProducer getSource() { return new ImageProducer() { Vector consumers = new Vector(); public void addConsumer(ImageConsumer ic) { if(!consumers.contains(ic)) consumers.add(ic); } public boolean isConsumer(ImageConsumer ic) { return consumers.contains(ic); } public void removeConsumer(ImageConsumer ic) { consumers.remove(ic); } public void startProduction(ImageConsumer ic) { int x = 0; int y = 0; int width = getWidth(); int height = getHeight(); int stride = width; int offset = 0; int[] pixels = getRGB(x, y, width, height, (int[])null, offset, stride); ColorModel model = getColorModel(); consumers.add(ic); for(int i=0;i<consumers.size();i++) { ImageConsumer c = (ImageConsumer) consumers.elementAt(i); c.setHints(ImageConsumer.SINGLEPASS); c.setDimensions(getWidth(), getHeight()); c.setPixels(x, y, width, height, model, pixels, offset, stride); c.imageComplete(ImageConsumer.STATICIMAGEDONE); } } public void requestTopDownLeftRightResend(ImageConsumer ic) { startProduction(ic); } }; } public Vector getSources() { return null; } public BufferedImage getSubimage(int x, int y, int w, int h) { WritableRaster subRaster = getRaster().createWritableChild(x, y, w, h, 0, 0, null); return new BufferedImage(getColorModel(), subRaster, isPremultiplied, properties); } public Raster getTile(int tileX, int tileY) { return getWritableTile(tileX, tileY); } public int getTileGridXOffset() { return 0; // according to javadocs } public int getTileGridYOffset() { return 0; // according to javadocs } public int getTileHeight() { return getHeight(); // image is one big tile } public int getTileWidth() { return getWidth(); // image is one big tile } public int getType() { return type; } public int getWidth() { return raster.getWidth(); } public int getWidth(ImageObserver imageobserver) { return getWidth(); } public WritableRaster getWritableTile(int tileX, int tileY) { isTileWritable(tileX, tileY); // for exception return raster; } private static final Point[] tileIndices = { new Point() }; public Point[] getWritableTileIndices() { return tileIndices; } public boolean hasTileWriters() { return true; } public boolean isAlphaPremultiplied() { return isPremultiplied; } public boolean isTileWritable(int tileX, int tileY) { if ((tileX != 0) || (tileY != 0)) throw new ArrayIndexOutOfBoundsException("only tile is (0,0)"); return true; } public void releaseWritableTile(int tileX, int tileY) { isTileWritable(tileX, tileY); // for exception } //public void removeTileObserver(TileObserver tileobserver) {} public void setData(Raster src) { int x = src.getMinX(); int y = src.getMinY(); int w = src.getWidth(); int h = src.getHeight(); // create a dest child that has the right bounds... WritableRaster dest = raster.createWritableChild(x, y, w, h, x, y, null // same bands ); if (src.getSampleModel () instanceof ComponentSampleModel && dest.getSampleModel () instanceof ComponentSampleModel) // Refer to ComponentDataBlitOp for optimized data blitting: ComponentDataBlitOp.INSTANCE.filter(src, dest); else { // slower path int samples[] = src.getPixels (x, y, w, h, (int [])null); dest.setPixels (x, y, w, h, samples); } } public void setRGB(int x, int y, int argb) { Object rgbElem = colorModel.getDataElements(argb, null); raster.setDataElements(x, y, rgbElem); } public void setRGB(int startX, int startY, int w, int h, int[] argbArray, int offset, int scanlineStride) { int endX = startX + w; int endY = startY + h; Object rgbElem = null; for (int y=startY; y<endY; y++) { int xoffset = offset; for (int x=startX; x<endX; x++) { int argb = argbArray[xoffset++]; rgbElem = colorModel.getDataElements(argb, rgbElem); raster.setDataElements(x, y, rgbElem); } offset += scanlineStride; } } public String toString() { StringBuffer buf; buf = new StringBuffer(/* estimated length */ 120); buf.append("BufferedImage@"); buf.append(Integer.toHexString(hashCode())); buf.append(": type="); buf.append(type); buf.append(' '); buf.append(colorModel); buf.append(' '); buf.append(raster); return buf.toString(); } /** * Adds a tile observer. If the observer is already present, it receives * multiple notifications. * * @param to The TileObserver to add. */ public void addTileObserver (TileObserver to) { if (observers == null) observers = new Vector (); observers.add (to); } /** * Removes a tile observer. If the observer was not registered, * nothing happens. If the observer was registered for multiple * notifications, it is now registered for one fewer notification. * * @param to The TileObserver to remove. */ public void removeTileObserver (TileObserver to) { if (observers == null) return; observers.remove (to); } /** * Return the transparency type. * * @return One of {@link #OPAQUE}, {@link #BITMASK}, or {@link #TRANSLUCENT}. * @see Transparency#getTransparency() * @since 1.5 */ public int getTransparency() { return colorModel.getTransparency(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -