⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pixelgrabber.java

📁 JAVA基本类源代码,大家可以学习学习!
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     * objects that was used by the ImageProducer to deliver the pixels.     * @return the ColorModel object used for storing the pixels     * @see #getStatus     * @see ColorModel#getRGBdefault     * @see #setColorModel(ColorModel)     */    public synchronized ColorModel getColorModel() {	return imageModel;    }    /**     * The setDimensions method is part of the ImageConsumer API which     * this class must implement to retrieve the pixels.     * <p>     * Note: This method is intended to be called by the ImageProducer     * of the Image whose pixels are being grabbed.  Developers using     * this class to retrieve pixels from an image should avoid calling     * this method directly since that operation could result in problems     * with retrieving the requested pixels.     * @param width the width of the dimension     * @param height the height of the dimension     */    public void setDimensions(int width, int height) {	if (dstW < 0) {	    dstW = width - dstX;	}	if (dstH < 0) {	    dstH = height - dstY;	}	if (dstW <= 0 || dstH <= 0) {	    imageComplete(STATICIMAGEDONE);	} else if (intPixels == null &&		   imageModel == ColorModel.getRGBdefault()) {	    intPixels = new int[dstW * dstH];	    dstScan = dstW;	    dstOff = 0;	}	flags |= (ImageObserver.WIDTH | ImageObserver.HEIGHT);    }    /**     * The setHints method is part of the ImageConsumer API which     * this class must implement to retrieve the pixels.     * <p>     * Note: This method is intended to be called by the ImageProducer     * of the Image whose pixels are being grabbed.  Developers using     * this class to retrieve pixels from an image should avoid calling     * this method directly since that operation could result in problems     * with retrieving the requested pixels.     * @param hints a set of hints used to process the pixels     */    public void setHints(int hints) {	return;    }    /**     * The setProperties method is part of the ImageConsumer API which     * this class must implement to retrieve the pixels.     * <p>     * Note: This method is intended to be called by the ImageProducer     * of the Image whose pixels are being grabbed.  Developers using     * this class to retrieve pixels from an image should avoid calling     * this method directly since that operation could result in problems     * with retrieving the requested pixels.     * @param props the list of properties     */    public void setProperties(Hashtable props) {	return;    }    /**     * The setColorModel method is part of the ImageConsumer API which     * this class must implement to retrieve the pixels.     * <p>     * Note: This method is intended to be called by the ImageProducer     * of the Image whose pixels are being grabbed.  Developers using     * this class to retrieve pixels from an image should avoid calling     * this method directly since that operation could result in problems     * with retrieving the requested pixels.     * @param model the specified <code>ColorModel</code>     * @see #getColorModel     */    public void setColorModel(ColorModel model) {	return;    }    private void convertToRGB() {	int size = dstW * dstH;	int newpixels[] = new int[size];	if (bytePixels != null) {	    for (int i = 0; i < size; i++) {		newpixels[i] = imageModel.getRGB(bytePixels[i] & 0xff);	    }	} else if (intPixels != null) {	    for (int i = 0; i < size; i++) {		newpixels[i] = imageModel.getRGB(intPixels[i]);	    }	}	bytePixels = null;	intPixels = newpixels;	dstScan = dstW;	dstOff = 0;	imageModel = ColorModel.getRGBdefault();    }    /**     * The setPixels method is part of the ImageConsumer API which     * this class must implement to retrieve the pixels.     * <p>     * Note: This method is intended to be called by the ImageProducer     * of the Image whose pixels are being grabbed.  Developers using     * this class to retrieve pixels from an image should avoid calling     * this method directly since that operation could result in problems     * with retrieving the requested pixels.     * @param srcX,&nbsp;srcY the coordinates of the upper-left corner     *        of the area of pixels to be set     * @param srcW the width of the area of pixels     * @param srcH the height of the area of pixels     * @param model the specified <code>ColorModel</code>     * @param pixels the array of pixels     * @param srcOff the offset into the pixels array     * @param srcScan the distance from one row of pixels to the next     *        in the pixels array     * @see #getPixels     */    public void setPixels(int srcX, int srcY, int srcW, int srcH,			  ColorModel model,			  byte pixels[], int srcOff, int srcScan) {	if (srcY < dstY) {	    int diff = dstY - srcY;	    if (diff >= srcH) {		return;	    }	    srcOff += srcScan * diff;	    srcY += diff;	    srcH -= diff;	}	if (srcY + srcH > dstY + dstH) {	    srcH = (dstY + dstH) - srcY;	    if (srcH <= 0) {		return;	    }	}	if (srcX < dstX) {	    int diff = dstX - srcX;	    if (diff >= srcW) {		return;	    }	    srcOff += diff;	    srcX += diff;	    srcW -= diff;	}	if (srcX + srcW > dstX + dstW) {	    srcW = (dstX + dstW) - srcX;	    if (srcW <= 0) {		return;	    }	}	int dstPtr = dstOff + (srcY - dstY) * dstScan + (srcX - dstX);	if (intPixels == null) {	    if (bytePixels == null) {		bytePixels = new byte[dstW * dstH];		dstScan = dstW;		dstOff = 0;		imageModel = model;	    } else if (imageModel != model) {		convertToRGB();	    }	    if (bytePixels != null) {		for (int h = srcH; h > 0; h--) {		    System.arraycopy(pixels, srcOff, bytePixels, dstPtr, srcW);		    srcOff += srcScan;		    dstPtr += dstScan;		}	    }	}	if (intPixels != null) {	    int dstRem = dstScan - srcW;	    int srcRem = srcScan - srcW;	    for (int h = srcH; h > 0; h--) {		for (int w = srcW; w > 0; w--) {		    intPixels[dstPtr++] = model.getRGB(pixels[srcOff++]&0xff);		}		srcOff += srcRem;		dstPtr += dstRem;	    }	}	flags |= ImageObserver.SOMEBITS;    }    /**     * The setPixels method is part of the ImageConsumer API which     * this class must implement to retrieve the pixels.     * <p>     * Note: This method is intended to be called by the ImageProducer     * of the Image whose pixels are being grabbed.  Developers using     * this class to retrieve pixels from an image should avoid calling     * this method directly since that operation could result in problems     * with retrieving the requested pixels.     * @param srcX,&nbsp;srcY the coordinates of the upper-left corner     *        of the area of pixels to be set     * @param srcW the width of the area of pixels     * @param srcH the height of the area of pixels     * @param model the specified <code>ColorModel</code>     * @param pixels the array of pixels     * @param srcOff the offset into the pixels array     * @param srcScan the distance from one row of pixels to the next     *        in the pixels array     * @see #getPixels     */    public void setPixels(int srcX, int srcY, int srcW, int srcH,			  ColorModel model,			  int pixels[], int srcOff, int srcScan) {	if (srcY < dstY) {	    int diff = dstY - srcY;	    if (diff >= srcH) {		return;	    }	    srcOff += srcScan * diff;	    srcY += diff;	    srcH -= diff;	}	if (srcY + srcH > dstY + dstH) {	    srcH = (dstY + dstH) - srcY;	    if (srcH <= 0) {		return;	    }	}	if (srcX < dstX) {	    int diff = dstX - srcX;	    if (diff >= srcW) {		return;	    }	    srcOff += diff;	    srcX += diff;	    srcW -= diff;	}	if (srcX + srcW > dstX + dstW) {	    srcW = (dstX + dstW) - srcX;	    if (srcW <= 0) {		return;	    }	}	if (intPixels == null) {	    if (bytePixels == null) {		intPixels = new int[dstW * dstH];		dstScan = dstW;		dstOff = 0;		imageModel = model;	    } else {		convertToRGB();	    }	}	int dstPtr = dstOff + (srcY - dstY) * dstScan + (srcX - dstX);	if (imageModel == model) {	    for (int h = srcH; h > 0; h--) {		System.arraycopy(pixels, srcOff, intPixels, dstPtr, srcW);		srcOff += srcScan;		dstPtr += dstScan;	    }	} else {	    if (imageModel != ColorModel.getRGBdefault()) {		convertToRGB();	    }	    int dstRem = dstScan - srcW;	    int srcRem = srcScan - srcW;	    for (int h = srcH; h > 0; h--) {		for (int w = srcW; w > 0; w--) {		    intPixels[dstPtr++] = model.getRGB(pixels[srcOff++]);		}		srcOff += srcRem;		dstPtr += dstRem;	    }	}	flags |= ImageObserver.SOMEBITS;    }    /**     * The imageComplete method is part of the ImageConsumer API which     * this class must implement to retrieve the pixels.     * <p>     * Note: This method is intended to be called by the ImageProducer     * of the Image whose pixels are being grabbed.  Developers using     * this class to retrieve pixels from an image should avoid calling     * this method directly since that operation could result in problems     * with retrieving the requested pixels.     * @param status the status of image loading     */    public synchronized void imageComplete(int status) {	grabbing = false;	switch (status) {	default:	case IMAGEERROR:	    flags |= ImageObserver.ERROR | ImageObserver.ABORT;	    break;	case IMAGEABORTED:	    flags |= ImageObserver.ABORT;	    break;	case STATICIMAGEDONE:	    flags |= ImageObserver.ALLBITS;	    break;	case SINGLEFRAMEDONE:	    flags |= ImageObserver.FRAMEBITS;	    break;	}	producer.removeConsumer(this);	notifyAll();    }    /**     * Returns the status of the pixels.  The ImageObserver flags     * representing the available pixel information are returned.     * This method and {@link #getStatus() getStatus} have the     * same implementation, but <code>getStatus</code> is the     * preferred method because it conforms to the convention of     * naming information-retrieval methods with the form     * "getXXX".     * @return the bitwise OR of all relevant ImageObserver flags     * @see ImageObserver     * @see #getStatus()     */      public synchronized int status() {	return flags;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -