List of usage examples for java.awt.image BufferedImage getType
public int getType()
From source file:org.deegree.securityproxy.wms.responsefilter.clipping.SimpleRasterClipper.java
private BufferedImage createOutputImage(BufferedImage inputImage, String format) { int inputImageWidth = inputImage.getWidth(); int inputImageHeight = inputImage.getHeight(); int inputImageType = inputImage.getType(); if (PNG_FORMAT.equals(format)) inputImageType = BufferedImage.TYPE_INT_ARGB; return new BufferedImage(inputImageWidth, inputImageHeight, inputImageType); }
From source file:org.elasticwarehouse.core.parsers.FileTools.java
public static FileThumb generateThumb(byte[] binaryContent, int metaimagewidth, int metaimageheight, int thumbsize) { FileThumb ret = new FileThumb(); if (binaryContent != null) { //String ftype = metadata_.getStringValueFor(ElasticWarehouseTikaMapper.FILETYPE, false); try {//from ww w . j a v a2 s .co m BufferedImage originalImage = ImageIO.read(new ByteArrayInputStream(binaryContent)); if (originalImage != null) { int type = originalImage.getType() == 0 ? BufferedImage.TYPE_INT_ARGB : originalImage.getType(); //int metaimagewidth = ParseTools.parseInt(metadata_.getStringValueFor(ElasticWarehouseTikaMapper.IMAGEWIDTH, false)); //int metaimageheight = ParseTools.parseInt(metadata_.getStringValueFor(ElasticWarehouseTikaMapper.IMAGEHEIGHT, false)); ret.orginalw = originalImage.getWidth(); ret.orginalh = originalImage.getHeight(); //int thumbsize = 180; //thumbsize = conf_.getWarehouseIntValue(ElasticWarehouseConf.THUMBSIZE, thumbsize); //if( thumbsize != 90 && thumbsize != 180 && thumbsize != 360 && thumbsize != 720) // thumbsize = 180; if (ret.orginalw <= thumbsize) { ret.sameasimage = true; } else { ret.sameasimage = false; ret.thumb_ = resizeImageWithHint(originalImage, type, thumbsize, ret.orginalh * thumbsize / ret.orginalw); } ret.thumbavailable_ = true; ret.thumbdate_ = Calendar.getInstance().getTime(); /*thumbs_.put(90, resizeImageWithHint(originalImage, type, 90, h*90/w)); if( w>=180 ) thumbs_.put(180, resizeImageWithHint(originalImage, type, 180, h*180/w)); if( w>=360 ) thumbs_.put(360, resizeImageWithHint(originalImage, type, 360, h*360/w)); if( w>=720 ) thumbs_.put(720, resizeImageWithHint(originalImage, type, 720, h*720/w)); */ } } catch (IOException e) { EWLogger.logerror(e); e.printStackTrace(); ret.error_ = e.getMessage(); } catch (RuntimeException e) { //i.e. when New BMP version not implemented yet. exception occurs EWLogger.logerror(e); ret.error_ = e.getMessage(); } } return ret; }
From source file:org.elfinder.servlets.commands.ResizeCommand.java
/** * Rotation function: this could be better!!! Rotation point by point not so * fast but work well./* ww w . j a v a 2 s . com*/ * * @param BufferedImage */ private BufferedImage rotateCw(BufferedImage img) { int width = img.getWidth(); int height = img.getHeight(); BufferedImage newImage = new BufferedImage(height, width, img.getType()); for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { newImage.setRGB(height - 1 - j, i, img.getRGB(i, j)); } } return newImage; }
From source file:org.geoserver.wms.legendgraphic.ColorMapLegendCreator.java
private BufferedImage mergeRows(Queue<BufferedImage> legendsQueue) { // I am doing a straight cast since I know that I built this // dimension object by using the widths and heights of the various // bufferedimages for the various bkgColor map entries. final Dimension finalDimension = new Dimension(); final int numRows = legendsQueue.size(); finalDimension.setSize(Math.max(footerW, colorW + ruleW + labelW) + 2 * dx + 2 * margin, rowH * numRows + 2 * margin + (numRows - 1) * dy); final int totalWidth = (int) finalDimension.getWidth(); final int totalHeight = (int) finalDimension.getHeight(); BufferedImage finalLegend = ImageUtils.createImage(totalWidth, totalHeight, (IndexColorModel) null, transparent);//from ww w . ja v a 2 s . c o m /* * For RAMP type, only HORIZONTAL or VERTICAL condition is valid */ if (colorMapType == ColorMapType.RAMP) { final Map<Key, Object> hintsMap = new HashMap<Key, Object>(); Graphics2D finalGraphics = ImageUtils.prepareTransparency(transparent, backgroundColor, finalLegend, hintsMap); hintsMap.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); finalGraphics.setRenderingHints(hintsMap); int topOfRow = (int) (margin + 0.5); for (int i = 0; i < numRows; i++) { final BufferedImage img = legendsQueue.remove(); // draw the image finalGraphics.drawImage(img, (int) (margin + 0.5), topOfRow, null); topOfRow += img.getHeight() + dy; } if (this.layout == LegendLayout.HORIZONTAL) { BufferedImage newImage = new BufferedImage(totalHeight, totalWidth, finalLegend.getType()); Graphics2D g2 = newImage.createGraphics(); g2.rotate(-Math.PI / 2, 0, 0); g2.drawImage(finalLegend, null, -totalWidth, 0); finalLegend = newImage; g2.dispose(); finalGraphics.dispose(); } } else { List<RenderedImage> imgs = new ArrayList<RenderedImage>(legendsQueue); LegendMerger.MergeOptions options = new LegendMerger.MergeOptions(imgs, (int) dx, (int) dy, (int) margin, 0, backgroundColor, transparent, true, layout, rowWidth, rows, columnHeight, columns, null, false, false); finalLegend = LegendMerger.mergeRasterLegends(options); } return finalLegend; }
From source file:org.github.jipsg.sanselan.BaseSanselanTest.java
/** * Some quick and dirty image scaling - please note that for best performance * and quality you should use image rescaling libraries. *//*from ww w . j av a 2 s. co m*/ @Override public BufferedImage resample(BufferedImage bufferedImage, int width, int height) { Dimension imageDimension = new Dimension(bufferedImage.getWidth(), bufferedImage.getHeight()); Dimension boundaryDimension = new Dimension(width, height); Dimension scaledDimension = BufferedImageUtils.getScaledDimension(imageDimension, boundaryDimension); double scaleX = scaledDimension.getWidth() / bufferedImage.getWidth(); double scaleY = scaledDimension.getHeight() / bufferedImage.getHeight(); AffineTransform scaleTransform = AffineTransform.getScaleInstance(scaleX, scaleY); AffineTransformOp biLinearScaleOp = new AffineTransformOp(scaleTransform, AffineTransformOp.TYPE_BILINEAR); return biLinearScaleOp.filter(bufferedImage, new BufferedImage(scaledDimension.width, scaledDimension.height, bufferedImage.getType())); }
From source file:org.github.jipsg.sanselan.ImageConversionSanselanTest.java
/** * Convert images having a transparency layer (alpha-channel) to JPG. Without * further handling the alpha-channel will be rendered black. * The test fails with "org.apache.commons.imaging.ImageWriteException: This image format (Jpeg-Custom) cannot be written." */// w w w. java 2 s . co m @Test(expected = org.apache.commons.imaging.ImageWriteException.class) public void testWriteTransparentImagesAsJpeg() throws Exception { String formatName = "jpeg"; List<File> sourceImageFileList = new ArrayList<File>(); sourceImageFileList.add(getImageFile("gif", "test-image-transparent.gif")); sourceImageFileList.add(getImageFile("png", "test-image-transparent.png")); for (File sourceImageFile : sourceImageFileList) { BufferedImage bufferedImage = createBufferedImage(sourceImageFile); assertValidBufferedImage(bufferedImage); assertTrue("Expecting transparency", bufferedImage.getColorModel().hasAlpha()); assertTrue("Expecting ARGB color model", bufferedImage.getType() == BufferedImage.TYPE_INT_ARGB); File targetImageFile = createOutputFileName("testWriteTransparentImagesAsJpeg", sourceImageFile, formatName); writeBufferedImage(bufferedImage, formatName, targetImageFile); } }
From source file:org.github.jipsg.sanselan.ImageConversionSanselanTest.java
/** * Convert images having a transparency layer (alpha-channel) to JPG. Fill * the alpha-channel with Color.WHITE to have a useful image. * The test fails with "org.apache.commons.imaging.ImageWriteException: This image format (Jpeg-Custom) cannot be written." *//*from w w w .j ava 2 s . c o m*/ @Test(expected = org.apache.commons.imaging.ImageWriteException.class) public void testWriteTransparentImagesWithAlphaChannelHandlingAsJpeg() throws Exception { String formatName = "jpeg"; List<File> sourceImageFileList = new ArrayList<File>(); sourceImageFileList.add(getImageFile("gif", "test-image-transparent.gif")); sourceImageFileList.add(getImageFile("png", "test-image-transparent.png")); for (File sourceImageFile : sourceImageFileList) { BufferedImage bufferedImage = createBufferedImage(sourceImageFile); assertValidBufferedImage(bufferedImage); assertTrue("Expecting transparency", bufferedImage.getColorModel().hasAlpha()); assertTrue("Expecting ARGB color model", bufferedImage.getType() == BufferedImage.TYPE_INT_ARGB); BufferedImage rgbBufferedImage = new BufferedImage(bufferedImage.getWidth(), bufferedImage.getHeight(), BufferedImage.TYPE_INT_RGB); Graphics2D graphics = rgbBufferedImage.createGraphics(); graphics.drawImage(bufferedImage, 0, 0, null); graphics.dispose(); assertValidBufferedImage(rgbBufferedImage); assertFalse("Expecting no transparency", rgbBufferedImage.getColorModel().hasAlpha()); assertEquals("Expecting RGB color model", BufferedImage.TYPE_INT_RGB, rgbBufferedImage.getType()); File targetImageFile = createOutputFileName("testWriteTransparentImagesWithAlphaChannelHandlingAsJpeg", sourceImageFile, formatName); writeBufferedImage(bufferedImage, formatName, targetImageFile); } }
From source file:org.jahia.services.image.AbstractJava2DImageService.java
protected BufferedImage getDestImage(int newWidth, int newHeight, BufferedImage originalImage) { BufferedImage dest;//from w w w. j a v a2 s . co m if (originalImage.getColorModel() instanceof IndexColorModel) { // dest = new BufferedImage(newWidth, newHeight, originalImage.getType(), (IndexColorModel) originalImage.getColorModel()); dest = new BufferedImage(originalImage.getColorModel(), originalImage.getColorModel().createCompatibleWritableRaster(newWidth, newHeight), false, new Hashtable<Object, Object>()); } else { dest = new BufferedImage(newWidth, newHeight, originalImage.getType()); } return dest; }
From source file:org.jas.util.ImageUtils.java
public Image resize(Image image, int width, int height) { BufferedImage bufferedImage = (BufferedImage) image; int type = bufferedImage.getType() == 0 ? BufferedImage.TYPE_INT_ARGB : bufferedImage.getType(); BufferedImage resizedImage = new BufferedImage(width, height, type); Graphics2D g = resizedImage.createGraphics(); g.setComposite(AlphaComposite.Src); g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.drawImage(image, 0, 0, width, height, null); g.dispose();/* w w w. j a v a 2s.c o m*/ return resizedImage; }
From source file:org.jboss.arquillian.extension.screenRecorder.ScreenRecorder.java
private BufferedImage convertToType(BufferedImage sourceImage, int targetType) { BufferedImage image;/*w w w. ja va 2s.com*/ if (sourceImage.getType() == targetType) { image = sourceImage; } // otherwise create a new image of the target type and draw the new image else { image = new BufferedImage(sourceImage.getWidth(), sourceImage.getHeight(), targetType); image.getGraphics().drawImage(sourceImage, 0, 0, null); } return image; }