List of usage examples for java.awt.image BufferedImage TYPE_CUSTOM
int TYPE_CUSTOM
To view the source code for java.awt.image BufferedImage TYPE_CUSTOM.
Click Source Link
From source file:TextureByReference.java
public void setByReference(boolean b) { // double check that changing is necessary if (b != images[0].isByReference()) { // these are the same for all images so get info once int format = images[0].getFormat(); boolean yUp = images[0].isYUp(); // reset yUp on all the images // have to new ImageComponents because cannot set value for (int i = 0; i < images.length; i++) { // if the bImage type does not match currentType and we are // setting // to byRef we need to convert it BufferedImage bImage = images[i].getImage(); if (bImage.getType() != currentType && b) { // bImage = ImageOps.convertImage(bImage, currentType); if (currentType != BufferedImage.TYPE_CUSTOM) { bImage = ImageOps.convertImage(bImage, currentType); } else if (customType == this.TYPE_CUSTOM_RGBA) { bImage = ImageOps.convertToCustomRGBA(bImage); } else { bImage = ImageOps.convertToCustomRGB(bImage); }//from w w w.j ava 2s .c om } images[i] = new ImageComponent2D(format, bImage, b, yUp); images[i].setCapability(ImageComponent.ALLOW_IMAGE_READ); images[i].setCapability(ImageComponent.ALLOW_FORMAT_READ); } } }
From source file:TextureByReference.java
public void setImageTypeCustomRGBA() { currentType = BufferedImage.TYPE_CUSTOM; customType = this.TYPE_CUSTOM_RGBA; // only need to change images if we are byRef otherwise will change // them when we change to byRef if (images[0].isByReference()) { // this information is the same for all int format = images[0].getFormat(); boolean yUp = images[0].isYUp(); boolean byRef = true; for (int i = 0; i < images.length; i++) { BufferedImage bImage = images[i].getImage(); bImage = ImageOps.convertToCustomRGBA(bImage); images[i] = new ImageComponent2D(format, bImage, byRef, yUp); images[i].setCapability(ImageComponent.ALLOW_IMAGE_READ); images[i].setCapability(ImageComponent.ALLOW_FORMAT_READ); }/*from w w w . j av a 2 s.c o m*/ } }
From source file:TextureByReference.java
public void setImageTypeCustomRGB() { currentType = BufferedImage.TYPE_CUSTOM; customType = this.TYPE_CUSTOM_RGB; // only need to change images if we are byRef otherwise will change // them when we change to byRef if (images[0].isByReference()) { // this information is the same for all int format = images[0].getFormat(); boolean yUp = images[0].isYUp(); boolean byRef = true; for (int i = 0; i < images.length; i++) { BufferedImage bImage = images[i].getImage(); bImage = ImageOps.convertToCustomRGB(bImage); images[i] = new ImageComponent2D(format, bImage, byRef, yUp); images[i].setCapability(ImageComponent.ALLOW_IMAGE_READ); images[i].setCapability(ImageComponent.ALLOW_FORMAT_READ); }// w w w. j a va 2 s . c om } }
From source file:TextureByReference.java
static void printType(BufferedImage bImage) { int type = bImage.getType(); if (type == BufferedImage.TYPE_4BYTE_ABGR) { System.out.println("TYPE_4BYTE_ABGR"); } else if (type == BufferedImage.TYPE_INT_ARGB) { System.out.println("TYPE_INT_ARGB"); } else if (type == BufferedImage.TYPE_3BYTE_BGR) { System.out.println("TYPE_3BYTE_BGR"); } else if (type == BufferedImage.TYPE_CUSTOM) { System.out.println("TYPE_CUSTOM"); } else/*from w w w .j a v a 2s. co m*/ System.out.println(type); }
From source file:org.codice.alliance.imaging.chip.transformer.CatalogOutputAdapter.java
private void setImageDataFields(BufferedImage chip, ImageSegment chipImageSegment) throws IOException { int[] componentSizes = chip.getColorModel().getComponentSize(); int pixelSize = chip.getColorModel().getPixelSize(); switch (chip.getType()) { case BufferedImage.TYPE_BYTE_GRAY: case BufferedImage.TYPE_USHORT_GRAY: case BufferedImage.TYPE_BYTE_BINARY: setMonochrome(chipImageSegment, componentSizes[0], pixelSize); break;/*from w w w . j a v a 2 s. c o m*/ case BufferedImage.TYPE_3BYTE_BGR: case BufferedImage.TYPE_INT_BGR: setImageFieldHelper(chipImageSegment, PixelValueType.INTEGER, ImageRepresentation.RGBTRUECOLOUR, componentSizes[0], pixelSize / 3, new String[] { "B", "G", "R" }); break; case BufferedImage.TYPE_4BYTE_ABGR: case BufferedImage.TYPE_4BYTE_ABGR_PRE: setImageFieldHelper(chipImageSegment, PixelValueType.INTEGER, ImageRepresentation.RGBTRUECOLOUR, componentSizes[0], pixelSize / 4, new String[] { "B", "G", "R" }); break; case BufferedImage.TYPE_INT_ARGB_PRE: case BufferedImage.TYPE_INT_ARGB: setARGB(chipImageSegment, componentSizes[0], pixelSize); break; case BufferedImage.TYPE_INT_RGB: case BufferedImage.TYPE_USHORT_555_RGB: setRGB(chipImageSegment, componentSizes[0], pixelSize); break; case BufferedImage.TYPE_CUSTOM: if (componentSizes.length == 1) { setMonochrome(chipImageSegment, componentSizes[0], pixelSize); } else if (componentSizes.length == 3) { setRGB(chipImageSegment, componentSizes[0], pixelSize); } else if (componentSizes.length == 4) { setARGB(chipImageSegment, componentSizes[0], pixelSize); } else { throw new IOException( "unsupported color model for image type CUSTOM, only monochrome and 32-bit argb are supported"); } break; case BufferedImage.TYPE_BYTE_INDEXED: setImageFieldHelper(chipImageSegment, PixelValueType.INTEGER, ImageRepresentation.RGBLUT, componentSizes[0], pixelSize, new String[] { "LU" }); break; case BufferedImage.TYPE_USHORT_565_RGB: // don't know how to handle this one, since the bitsPerPixelPerBand is not consistent break; default: throw new IOException("unsupported image data type: type=" + chip.getType()); } }
From source file:org.ofbiz.product.imagemanagement.ImageManagementServices.java
public static Map<String, Object> resizeImageThumbnail(BufferedImage bufImg, double imgHeight, double imgWidth) { /* VARIABLES */ BufferedImage bufNewImg;//from w w w . java 2 s . c om double defaultHeight, defaultWidth, scaleFactor; Map<String, Object> result = FastMap.newInstance(); /* DIMENSIONS from ImageProperties */ defaultHeight = 100; defaultWidth = 100; /* SCALE FACTOR */ // find the right Scale Factor related to the Image Dimensions if (imgHeight > imgWidth) { scaleFactor = defaultHeight / imgHeight; // get scaleFactor from the smallest width if (defaultWidth < (imgWidth * scaleFactor)) { scaleFactor = defaultWidth / imgWidth; } } else { scaleFactor = defaultWidth / imgWidth; // get scaleFactor from the smallest height if (defaultHeight < (imgHeight * scaleFactor)) { scaleFactor = defaultHeight / imgHeight; } } int bufImgType; if (BufferedImage.TYPE_CUSTOM == bufImg.getType()) { // apply a type for image majority bufImgType = BufferedImage.TYPE_INT_ARGB_PRE; } else { bufImgType = bufImg.getType(); } // scale original image with new size Image newImg = bufImg.getScaledInstance((int) (imgWidth * scaleFactor), (int) (imgHeight * scaleFactor), Image.SCALE_SMOOTH); bufNewImg = ImageTransform.toBufferedImage(newImg, bufImgType); result.put("bufferedImage", bufNewImg); result.put("scaleFactor", scaleFactor); return result; }
From source file:org.ofbiz.product.imagemanagement.ImageManagementServices.java
public static Map<String, Object> resizeImage(BufferedImage bufImg, double imgHeight, double imgWidth, double resizeHeight, double resizeWidth) { /* VARIABLES */ BufferedImage bufNewImg;//w w w. j a va 2 s.c om double defaultHeight, defaultWidth, scaleFactor; Map<String, Object> result = FastMap.newInstance(); /* DIMENSIONS from ImageProperties */ defaultHeight = resizeHeight; defaultWidth = resizeWidth; /* SCALE FACTOR */ // find the right Scale Factor related to the Image Dimensions if (imgHeight > imgWidth) { scaleFactor = defaultHeight / imgHeight; // get scaleFactor from the smallest width if (defaultWidth < (imgWidth * scaleFactor)) { scaleFactor = defaultWidth / imgWidth; } } else { scaleFactor = defaultWidth / imgWidth; // get scaleFactor from the smallest height if (defaultHeight < (imgHeight * scaleFactor)) { scaleFactor = defaultHeight / imgHeight; } } int bufImgType; if (BufferedImage.TYPE_CUSTOM == bufImg.getType()) { // apply a type for image majority bufImgType = BufferedImage.TYPE_INT_ARGB_PRE; } else { bufImgType = bufImg.getType(); } // scale original image with new size Image newImg = bufImg.getScaledInstance((int) (imgWidth * scaleFactor), (int) (imgHeight * scaleFactor), Image.SCALE_SMOOTH); bufNewImg = ImageTransform.toBufferedImage(newImg, bufImgType); result.put("bufferedImage", bufNewImg); result.put("scaleFactor", scaleFactor); return result; }
From source file:org.olat.core.commons.services.image.spi.ImageHelperImpl.java
/** * This code is very inspired on Chris Campbells article "The Perils of Image.getScaledInstance()" * * The article can be found here:/*from w w w . j a va 2 s.c o m*/ * http://today.java.net/pub/a/today/2007/04/03/perils-of-image-getscaledinstance.html * * Note that the filter method is threadsafe */ private static BufferedImage scaleFastTo(BufferedImage img, Size scaledSize) { if (!scaledSize.isChanged()) return img; BufferedImage dest; if (img.getType() == BufferedImage.TYPE_CUSTOM) { dest = new BufferedImage(scaledSize.getWidth(), scaledSize.getHeight(), BufferedImage.TYPE_INT_ARGB); } else { dest = new BufferedImage(scaledSize.getWidth(), scaledSize.getHeight(), img.getType()); } int dstWidth = scaledSize.getWidth(); int dstHeight = scaledSize.getHeight(); BufferedImage ret = img; int w, h; // Use multi-step technique: start with original size, then // scale down in multiple passes with drawImage() // until the target size is reached w = img.getWidth(); h = img.getHeight(); int x = scaledSize.getXOffset(); int y = scaledSize.getYOffset(); //crop the image to see only the center of the image if (x > 0 || y > 0) { ret = img.getSubimage(x, y, w - (2 * x), h - (2 * y)); } do { if (w > dstWidth) { if (x > 0) { x /= 2; } w /= 2; if (w < dstWidth) { w = dstWidth; } } else { w = dstWidth; } if (h > dstHeight) { h /= 2; if (h < dstHeight) { h = dstHeight; } } else { h = dstHeight; } BufferedImage tmp; if (dest.getWidth() == w && dest.getHeight() == h && w == dstWidth && h == dstHeight) { tmp = dest; } else { tmp = new BufferedImage(w, h, dest.getType()); } Graphics2D g2 = tmp.createGraphics(); g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g2.drawImage(ret, 0, 0, w, h, null); g2.dispose(); ret = tmp; } while (w != dstWidth || h != dstHeight); return ret; }
From source file:org.sbs.util.ImageCompress.java
/** * ?//from w w w. j a v a2s.com * * @param source * @param targetW * @param targetH * @return */ public BufferedImage resize(BufferedImage source, int targetW, int targetH) { // targetWtargetH int desH = 0; int type = source.getType(); BufferedImage target = null; double sx = (double) targetW / source.getWidth(); double sy = sx; desH = (int) (sx * source.getHeight()); if (desH < targetH) { desH = targetH; sy = (double) 61 / source.getHeight(); } if (type == BufferedImage.TYPE_CUSTOM) { // handmade ColorModel cm = source.getColorModel(); WritableRaster raster = cm.createCompatibleWritableRaster(targetW, desH); boolean alphaPremultiplied = cm.isAlphaPremultiplied(); target = new BufferedImage(cm, raster, alphaPremultiplied, null); } else target = new BufferedImage(targetW, desH, type); Graphics2D g = target.createGraphics(); // smoother than exlax: g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g.drawRenderedImage(source, AffineTransform.getScaleInstance(sx, sy)); g.dispose(); return target; }