ImageFilter filter = new GrayFilter(true, 50); ImageProducer producer = new FilteredImageSource(colorImage.getSource(), filter); Image mage = Toolkit.getDefaultToolkit().createImage(producer);
/** * Creates an indexed version of the given image (a {@code BufferedImage} * with an {@code IndexColorModel}. * The resulting image will have a maximum of 256 different colors. * Transparent parts of the original will be replaced with solid black. * Default (possibly HW accelerated) dither will be used. * * @param pImage the image to convert * * @return an indexed version of the given image */ public static BufferedImage createIndexed(Image pImage) { return IndexImage.getIndexedImage(toBuffered(pImage), 256, Color.black, IndexImage.DITHER_DEFAULT); }
protected RenderedImage doFilter(BufferedImage pImage, ServletRequest pRequest, ImageServletResponse pResponse) { // Filter Image img = ImageUtil.filter(pImage, imageFilter); // Create BufferedImage & return return ImageUtil.toBuffered(img, BufferedImage.TYPE_INT_RGB); // TODO: This is ok for JPEG only... } }
/** * Rotates the image to the given angle. Areas not covered with pixels from * the source image will be left transparent, if possible. * * @param pImage the source image * @param pAngle the angle of rotation, in radians * * @return a new {@code BufferedImage}, unless {@code pAngle == 0.0} */ public static BufferedImage createRotated(final Image pImage, final double pAngle) { return createRotated0(toBuffered(pImage), pAngle); }
/** * Converts an image to grayscale. * * @see GrayFilter * @see RGBImageFilter * * @param pOriginal the image to convert. * @return a new Image, containing the gray image data. */ public static Image grayscale(Image pOriginal) { // Create filter RGBImageFilter filter = new GrayFilter(); // Convert to gray return filter(pOriginal, filter); }
/** * Adds contrast * * @param pOriginal the BufferedImage to add contrast to * * @return an {@code Image}, containing the contrasted image. */ public static Image contrast(Image pOriginal) { return contrast(pOriginal, 0.3f); }
/** * Tries to use H/W-accelerated code for an image for display purposes. * Note that transparent parts of the image might be replaced by solid * color. Additional image information not used by the current diplay * hardware may be discarded, like extra bith depth etc. * * @param pImage any {@code Image} * @return a {@code BufferedImage} */ public static BufferedImage accelerate(Image pImage) { return accelerate(pImage, null, DEFAULT_CONFIGURATION); }
/** * Creates a blurred version of the given image. * * @param pOriginal the original image * * @return a new {@code BufferedImage} with a blurred version of the given image */ public static BufferedImage blur(BufferedImage pOriginal) { return blur(pOriginal, 1.5f); }
/** * Creates a compatible {@code Raster} to dither into. * Only {@code IndexColorModel} allowed. * * @param pSrc * * @return a {@code WritableRaster} */ public final WritableRaster createCompatibleDestRaster(Raster pSrc) { return createCompatibleDestRaster(pSrc, getICM(pSrc)); }
/** * Creates a compatible {@code Raster} to dither into. * Only {@code IndexColorModel} allowed. * * @param pSrc the source raster * * @return a {@code WritableRaster} */ public final WritableRaster createCompatibleDestRaster(Raster pSrc) { return createCompatibleDestRaster(pSrc, getICM(pSrc)); }
/** * @param pRGBColorMap the rgb color map to create inverse color map for. * @param pTransparent the index of the transparent pixel in the map */ InverseColorMap(byte[] pRGBColorMap, int pTransparent) { rgbMapByte = pRGBColorMap; numColors = rgbMapByte.length / 4; transparentIndex = pTransparent; inverseRGB = new byte[MAXQUANTVAL * MAXQUANTVAL * MAXQUANTVAL]; initIRGB(new int[MAXQUANTVAL * MAXQUANTVAL * MAXQUANTVAL]); }
/** * Frees resources used by this {@code BufferedImageFactory}. */ public void dispose() { freeResources(); buffered = null; colorModel = null; }
public void setDimensions(int pWidth, int pHeight) { if (width < 0) { width = pWidth - x; } if (height < 0) { height = pHeight - y; } // Hmm.. Special case, but is it a good idea? if (width <= 0 || height <= 0) { imageComplete(ImageConsumer.STATICIMAGEDONE); } }
private static double bessel(final double t) { if (t == 0.0) { return Math.PI / 4.0; } return besselOrderOne(Math.PI * t) / (2.0 * t); }
private void processProgress(int scanline) { if (listeners != null) { int percent = 100 * scanline / height; if (percent > percentageDone) { percentageDone = percent; for (ProgressListener listener : listeners) { listener.progress(this, percent); } } } }
/** * @param pImage the image to get {@code IndexColorModel} from * @param pNumberOfColors the number of colors for the {@code IndexColorModel} * @param pFast {@code true} if fast * @return an {@code IndexColorModel} * @see #getIndexColorModel(Image,int,int) * * @deprecated Use {@link #getIndexColorModel(Image,int,int)} instead! * This version will be removed in a later version of the API. */ public static IndexColorModel getIndexColorModel(Image pImage, int pNumberOfColors, boolean pFast) { return getIndexColorModel(pImage, pNumberOfColors, pFast ? COLOR_SELECTION_FAST : COLOR_SELECTION_QUALITY); }
public void progress(BufferedImageFactory pFactory, float pPercentage) { if (pPercentage > 5) { pFactory.abort(); } } });
/** * @param pRGBColorMap the rgb color map to create inverse color map for. * @param pTransparent the index of the transparent pixel in the map */ InverseColorMap(int[] pRGBColorMap, int pTransparent) { rgbMapInt = pRGBColorMap; numColors = rgbMapInt.length; transparentIndex = pTransparent; inverseRGB = new byte[MAXQUANTVAL * MAXQUANTVAL * MAXQUANTVAL]; initIRGB(new int[MAXQUANTVAL * MAXQUANTVAL * MAXQUANTVAL]); }
private void createColorModel() { colorModel = sourceColorModel; // Clean up, in case any objects are copied/cloned, so we can free resources freeResources(); }
/** * Aborts the image production. */ public void abort() { consumer.imageComplete(ImageConsumer.IMAGEABORTED); }