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:ImageUtil.java
/** * create new image from source image// w ww .j a v a 2 s. co m * @param srcImg source image * @param targetWidth target image width * @param targetHeight target image height * @return new image with specify width and height */ public static BufferedImage createNewImage(BufferedImage srcImg, int targetWidth, int targetHeight) { BufferedImage targetImg = null; int type = srcImg.getType(); if (type == BufferedImage.TYPE_CUSTOM) { ColorModel cm = srcImg.getColorModel(); WritableRaster raster = cm.createCompatibleWritableRaster(targetWidth, targetHeight); boolean alphaPremultiplied = cm.isAlphaPremultiplied(); targetImg = new BufferedImage(cm, raster, alphaPremultiplied, null); } else { targetImg = new BufferedImage(targetWidth, targetHeight, type); } return targetImg; }
From source file:common.utils.ImageUtils.java
/** * resize input image to new dinesions(only smaller) and save it to file * @param image input image for scaling * @param scale_factor factor for scaling image * @param rez writes resulting image to a file * @throws IOException// w w w .j a v a 2 s .com */ public static void saveScaledImageWidth(BufferedImage image, double scale_factor, OutputStream rez) throws IOException { //long time_resize = System.currentTimeMillis(); if (scale_factor == 1) { writeImage(image, 1, rez); } else { int width = (int) (scale_factor * image.getWidth()); int height = (int) (scale_factor * image.getHeight()); //BufferedImage scaled_bi = new BufferedImage( image.getWidth(), image.getHeight(), image.getType() ); int type = image.getType(); BufferedImage scaled_bi; if (type == BufferedImage.TYPE_CUSTOM) { scaled_bi = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR); } else { scaled_bi = new BufferedImage(width, height, type); } Graphics2D g2 = scaled_bi.createGraphics(); //g2.drawImage(image, at, null); g2.drawImage(image.getScaledInstance(width, height, Image.SCALE_SMOOTH), 0, 0, null); writeImage(scaled_bi, 1, rez); g2.dispose(); } //time_resize = System.currentTimeMillis() - time_resize; //System.out.print("time_resize=" + (time_resize) + "; "); }
From source file:ImageBouncer.java
public void setImageType(String s) { int type = BufferedImage.TYPE_CUSTOM; if (s.equals("TYPE_INT_RGB")) type = BufferedImage.TYPE_INT_RGB; else if (s.equals("TYPE_INT_ARGB")) type = BufferedImage.TYPE_INT_ARGB; else if (s.equals("TYPE_INT_ARGB_PRE")) type = BufferedImage.TYPE_INT_ARGB_PRE; else if (s.equals("TYPE_3BYTE_BGR")) type = BufferedImage.TYPE_3BYTE_BGR; else if (s.equals("TYPE_BYTE_GRAY")) type = BufferedImage.TYPE_BYTE_GRAY; else if (s.equals("TYPE_USHORT_GRAY")) type = BufferedImage.TYPE_USHORT_GRAY; else if (s.equals("TYPE_USHORT_555_RGB")) type = BufferedImage.TYPE_USHORT_565_RGB; else if (s.equals("TYPE_USHORT_565_RGB")) type = BufferedImage.TYPE_USHORT_565_RGB; else {/*from ww w .j ava 2s. c om*/ System.out.println("Unrecognized type."); return; } image = makeBufferedImage(mOriginalImage, type); }
From source file:com.flexive.shared.media.impl.FxMediaNativeEngine.java
public static BufferedImage scale(BufferedImage bi, int width, int height) { BufferedImage bi2;/*from w w w. j av a2 s .co m*/ int scaleWidth = bi.getWidth(null); int scaleHeight = bi.getHeight(null); double scaleX = (double) width / scaleWidth; double scaleY = (double) height / scaleHeight; double scale = Math.min(scaleX, scaleY); scaleWidth = (int) ((double) scaleWidth * scale); scaleHeight = (int) ((double) scaleHeight * scale); Image scaledImage; if (HEADLESS) { // create a new buffered image, don't rely on a local graphics system (headless mode) final int type; if (bi.getType() != BufferedImage.TYPE_CUSTOM) { type = bi.getType(); } else if (bi.getAlphaRaster() != null) { // alpha channel available type = BufferedImage.TYPE_INT_ARGB; } else { type = BufferedImage.TYPE_INT_RGB; } bi2 = new BufferedImage(scaleWidth, scaleHeight, type); } else { GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice() .getDefaultConfiguration(); bi2 = gc.createCompatibleImage(scaleWidth, scaleHeight, bi.getTransparency()); } Graphics2D g = bi2.createGraphics(); if (scale < 0.3 && Math.max(scaleWidth, scaleHeight) < 500) { scaledImage = bi.getScaledInstance(scaleWidth, scaleHeight, Image.SCALE_SMOOTH); new ImageIcon(scaledImage).getImage(); g.drawImage(scaledImage, 0, 0, scaleWidth, scaleHeight, null); } else { g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g.drawImage(bi, 0, 0, scaleWidth, scaleHeight, null); } g.dispose(); return bi2; }
From source file:com.fengduo.bee.service.impl.file.FileServiceImpl.java
/** * ?//from w w w . j av a 2 s .c om * * @param source * @param targetW * @param targetH * @param ifScaling ? * @return */ public static BufferedImage resize(BufferedImage source, int targetW, int targetH, boolean ifScaling) { // targetWtargetH int type = source.getType(); BufferedImage target = null; double sx = (double) targetW / source.getWidth(); double sy = (double) targetH / source.getHeight(); // targetWtargetH??,?if else??? if (ifScaling) { if (sx > sy) { sx = sy; targetW = (int) (sx * source.getWidth()); } else { sy = sx; targetH = (int) (sy * source.getHeight()); } } if (type == BufferedImage.TYPE_CUSTOM) { // handmade ColorModel cm = source.getColorModel(); WritableRaster raster = cm.createCompatibleWritableRaster(targetW, targetH); boolean alphaPremultiplied = cm.isAlphaPremultiplied(); target = new BufferedImage(cm, raster, alphaPremultiplied, null); } else target = new BufferedImage(targetW, targetH, type); Graphics2D g = target.createGraphics(); // smoother than exlax: g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g.drawRenderedImage(source, AffineTransform.getScaleInstance(sx, sy)); g.dispose(); return target; }
From source file:org.geomajas.plugin.rasterizing.layer.RasterDirectLayer.java
private BufferedImage makeOpaque(BufferedImage image) { if (image.getType() == BufferedImage.TYPE_CUSTOM) { log.warn("makeOpaque {} Unknown Image Type 0: ", getTitle()); return image; }//from www.j av a 2s . c o m BufferedImage opaqueCopy = new BufferedImage(image.getWidth(), image.getHeight(), image.getType()); Graphics2D g1 = opaqueCopy.createGraphics(); g1.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getOpacity())); g1.drawImage(image, null, 0, 0); g1.dispose(); return opaqueCopy; }
From source file:com.fluidops.iwb.deepzoom.DZConvert.java
static int getType(BufferedImage img) { if (img.getType() == BufferedImage.TYPE_CUSTOM) return BufferedImage.TYPE_INT_ARGB_PRE; else//from w w w. jav a 2 s. co m return img.getType(); }
From source file:TextureByReference.java
public void setFlipImages(boolean b) { // double check that flipping is necessary if (b != flip) { BufferedImage bImage;/*w ww. j a va 2 s. c o m*/ // these are the same for all images so get info once int format = images[0].getFormat(); boolean byRef = images[0].isByReference(); boolean yUp = images[0].isYUp(); // flip all the images // have to new ImageComponents because can't set the image at // runtime for (int i = 0; i < images.length; i++) { bImage = images[i].getImage(); ImageOps.flipImage(bImage); // if we are byRef and the bImage type does not match // currentType // we need to convert it. If we are not byRef we will // save converting until it is changed to byRef if (byRef && bImage.getType() != 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); } } images[i] = new ImageComponent2D(format, bImage, byRef, yUp); images[i].setCapability(ImageComponent.ALLOW_IMAGE_READ); images[i].setCapability(ImageComponent.ALLOW_FORMAT_READ); } // set flip to new value flip = b; } }
From source file:com.funambol.foundation.util.MediaUtils.java
/** * Rotates given buffered image by given amount of degree. * The valid degree values are 0, 90, 180, 270. * If the image is a jpg, the rotation is lossless, exif data are preserved * and image size is almost the same.//from w ww. ja v a 2 s .c o m * * @param bufImage the buffered image * @param degree amount of degree to apply * @return a buffered image containing rotated image data * @throws PicturesException if amount of degree is invalid or if an * IOException occurs */ private static BufferedImage rotateImage(BufferedImage bufImage, int degree) throws FileDataObjecyUtilsException { degree = degree % 360; int h; int w; switch (degree) { case 0: case 180: h = bufImage.getHeight(); w = bufImage.getWidth(); break; case 90: case 270: h = bufImage.getWidth(); w = bufImage.getHeight(); break; default: throw new FileDataObjecyUtilsException( "Error rotating image since the '" + degree + "' degree value is unsupported"); } BufferedImage out = null; int bufImageType = bufImage.getType(); if (BufferedImage.TYPE_BYTE_INDEXED == bufImageType || BufferedImage.TYPE_BYTE_BINARY == bufImageType) { IndexColorModel model = (IndexColorModel) bufImage.getColorModel(); out = new BufferedImage(w, h, bufImage.getType(), model); } else if (BufferedImage.TYPE_CUSTOM == bufImageType) { // we don't know what type of image it can be // there's a bug in some VM that cause some PNG images to have // type custom: this should take care of this issue //check if we need to have alpha channel boolean alpha = bufImage.getTransparency() != BufferedImage.OPAQUE; if (alpha) { // TYPE_INT_ARGB_PRE gives you smaller output images // than TYPE_INT_ARGB out = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB_PRE); } else { out = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); } } else { out = new BufferedImage(w, h, bufImage.getType()); } Graphics2D g2d = out.createGraphics(); Map renderingHints = new HashMap(); renderingHints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); renderingHints.put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g2d.setRenderingHints(renderingHints); g2d.rotate(Math.toRadians(degree)); switch (degree) { case 90: g2d.translate(0, -w); break; case 180: g2d.translate(-w, -h); break; case 270: g2d.translate(-h, 0); break; } g2d.drawImage(bufImage, null, 0, 0); g2d.dispose(); return out; }
From source file:TextureByReference.java
public void setYUp(boolean b) { // double check that changing yUp is necessary if (b != images[0].isYUp()) { // these are the same for all images so get info once int format = images[0].getFormat(); boolean byRef = images[0].isByReference(); // reset yUp on all the images -- have to new ImageComponents // because // cannot change the value at runtime for (int i = 0; i < images.length; i++) { // if we are byRef and the bImage type does not match // currentType // we need to convert it. If we are not byRef we will // save converting until it is changed to byRef BufferedImage bImage = images[i].getImage(); if (byRef && bImage.getType() != currentType) { // 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 a v a 2s . c om } images[i] = new ImageComponent2D(format, bImage, byRef, b); images[i].setCapability(ImageComponent.ALLOW_IMAGE_READ); images[i].setCapability(ImageComponent.ALLOW_FORMAT_READ); } } }