List of usage examples for java.awt.image BufferedImage TYPE_INT_ARGB
int TYPE_INT_ARGB
To view the source code for java.awt.image BufferedImage TYPE_INT_ARGB.
Click Source Link
From source file:org.codice.imaging.nitf.render.RenderTestSupport.java
private BufferedImage convert2ARGB(ImageSegment imageSegment, BufferedImage bufferedImage) { BufferedImage imgAGRB = new BufferedImage( imageSegment.getImageLocationColumn() + (int) imageSegment.getNumberOfColumns(), imageSegment.getImageLocationRow() + (int) imageSegment.getNumberOfRows(), BufferedImage.TYPE_INT_ARGB); Graphics2D targetGraphic = imgAGRB.createGraphics(); targetGraphic.drawImage(bufferedImage, 0, 0, null); return imgAGRB; }
From source file:com.openbravo.pos.util.ThumbNailBuilder.java
private Image createThumbNail(Image img) { // MaskFilter filter = new MaskFilter(Color.WHITE); // ImageProducer prod = new FilteredImageSource(img.getSource(), filter); // img = Toolkit.getDefaultToolkit().createImage(prod); int targetw;// w ww . ja v a 2 s. com int targeth; double scalex = (double) m_width / (double) img.getWidth(null); double scaley = (double) m_height / (double) img.getHeight(null); if (scalex < scaley) { targetw = m_width; targeth = (int) (img.getHeight(null) * scalex); } else { targetw = (int) (img.getWidth(null) * scaley); targeth = (int) m_height; } int midw = img.getWidth(null); int midh = img.getHeight(null); BufferedImage midimg = null; Graphics2D g2d = null; Image previmg = img; int prevw = img.getWidth(null); int prevh = img.getHeight(null); do { if (midw > targetw) { midw /= 2; if (midw < targetw) { midw = targetw; } } else { midw = targetw; } if (midh > targeth) { midh /= 2; if (midh < targeth) { midh = targeth; } } else { midh = targeth; } if (midimg == null) { midimg = new BufferedImage(midw, midh, BufferedImage.TYPE_INT_ARGB); g2d = midimg.createGraphics(); g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); } g2d.drawImage(previmg, 0, 0, midw, midh, 0, 0, prevw, prevh, null); prevw = midw; prevh = midh; previmg = midimg; } while (midw != targetw || midh != targeth); g2d.dispose(); if (m_width != midimg.getWidth() || m_height != midimg.getHeight()) { midimg = new BufferedImage(m_width, m_height, BufferedImage.TYPE_INT_ARGB); int x = (m_width > targetw) ? (m_width - targetw) / 2 : 0; int y = (m_height > targeth) ? (m_height - targeth) / 2 : 0; g2d = midimg.createGraphics(); g2d.drawImage(previmg, x, y, x + targetw, y + targeth, 0, 0, targetw, targeth, null); g2d.dispose(); previmg = midimg; } return previmg; }
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." *///from w w w . j av a 2 s .c om @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:io.github.karols.hocr4j.PageRenderer.java
/** * Renders this page on a blank image.//from w w w.jav a 2s . c om * The image is filled with the background color. * * @param page page to render * @return rendered image */ @Nonnull public BufferedImage renderOnBlank(@Nonnull Page page) { Bounds pageBounds = page.getBounds().scale(scale); BufferedImage img = new BufferedImage(pageBounds.getRight(), pageBounds.getBottom(), BufferedImage.TYPE_INT_ARGB); Graphics g = img.getGraphics(); g.setColor(backgroundColor); g.fillRect(0, 0, img.getWidth(), img.getHeight()); renderOnTop(page, img); return img; }
From source file:nl.b3p.kaartenbalie.core.server.b3pLayering.ConfigLayer.java
protected BufferedImage createBaseImage(OGCRequest ogcrequest, Map parameterMap) throws Exception { Boolean transparant = (Boolean) parameterMap.get("transparant"); // Image width & heigth... int width = Integer.parseInt(ogcrequest.getParameter(OGCConstants.WMS_PARAM_WIDTH)); int height = Integer.parseInt(ogcrequest.getParameter(OGCConstants.WMS_PARAM_HEIGHT)); BufferedImage bufImage = null; bufImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = bufImage.createGraphics(); if (!transparant.booleanValue()) { g2d.setColor(Color.WHITE); g2d.fillRect(0, 0, width, height); }/*from w ww .j a v a2 s . co m*/ return bufImage; }
From source file:net.mindengine.oculus.frontend.web.controllers.project.ProjectEditController.java
private String saveProjectIconFromBufferedImage(BufferedImage image, Long id) throws IOException { Date date = new Date(); String path = config.getDataFolder() + File.separator + "projects" + File.separator + id; new File(path).mkdirs(); File file = new File(path + File.separator + "icon_" + date.getTime() + ".png"); file.createNewFile();/*from w ww .jav a2s .co m*/ BufferedImage imageRGB = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB); imageRGB.setData(image.getData()); ImageIO.write(imageRGB, "png", file); return Long.toString(date.getTime()); }
From source file:CompositeTest.java
public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; BufferedImage image = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D gImage = image.createGraphics(); gImage.setPaint(Color.red);//from w w w .jav a2s. c o m gImage.fill(shape1); AlphaComposite composite = AlphaComposite.getInstance(rule, alpha); gImage.setComposite(composite); gImage.setPaint(Color.blue); gImage.fill(shape2); g2.drawImage(image, null, 0, 0); }
From source file:com.joliciel.jochre.graphics.SegmenterImpl.java
public void segment() { LOG.debug("########## segment #########"); if (currentMonitor != null) { currentMonitor.setCurrentAction("imageMonitor.findingShapes"); }/*from www. j av a 2 s .c o m*/ List<Shape> shapes = this.findContiguousShapes(sourceImage); if (this.isDrawSegmentation()) { segmentedImage = new BufferedImage(sourceImage.getWidth(), sourceImage.getHeight(), BufferedImage.TYPE_INT_ARGB); graphics2D = segmentedImage.createGraphics(); graphics2D.drawImage(sourceImage.getOriginalImage(), 0, 0, sourceImage.getWidth(), sourceImage.getHeight(), null); } this.removeSpecks(sourceImage, shapes); this.removeOversizedShapes(shapes); if (currentMonitor != null) { currentMonitor.setCurrentAction("imageMonitor.groupingShapesIntoRows"); currentMonitor.setPercentComplete(0.2); } List<Rectangle> whiteAreas = sourceImage.getWhiteAreas(shapes); // if (this.drawSegmentation) { // graphics2D.setStroke(new BasicStroke(1)); // graphics2D.setPaint(Color.ORANGE); // for (Rectangle whiteArea : whiteAreas) { // graphics2D.drawRect(whiteArea.getLeft(), whiteArea.getTop(), whiteArea.getRight() - whiteArea.getLeft(), whiteArea.getBottom()-whiteArea.getTop()); // } // } // first we group shapes into rows based on white areas which don't rely on knowledge of page slope // having the rows allows us to estimate page slope List<RowOfShapes> rows = this.groupShapesIntoRows(sourceImage, shapes, whiteAreas, false); this.addRowsToJochreImage(sourceImage, rows); this.findGuideLines(sourceImage); List<Rectangle> columnSeparators = sourceImage.findColumnSeparators(); if (this.drawSegmentation) { graphics2D.setStroke(new BasicStroke(3)); graphics2D.setPaint(Color.ORANGE); for (Rectangle whiteArea : columnSeparators) { int topLeft = (int) Math.round(whiteArea.getLeft() + sourceImage.getXAdjustment(whiteArea.getTop())) + 3; int bottomLeft = (int) Math .round(whiteArea.getLeft() + sourceImage.getXAdjustment(whiteArea.getBottom())) + 3; int topRight = (int) Math .round(whiteArea.getRight() + sourceImage.getXAdjustment(whiteArea.getTop())) - 3; int bottomRight = (int) Math .round(whiteArea.getRight() + sourceImage.getXAdjustment(whiteArea.getBottom())) - 3; graphics2D.drawLine(topLeft, whiteArea.getTop() + 3, bottomLeft, whiteArea.getBottom() - 3); graphics2D.drawLine(topRight, whiteArea.getTop() + 3, bottomRight, whiteArea.getBottom() - 3); graphics2D.drawLine(topLeft, whiteArea.getTop() + 3, topRight, whiteArea.getTop() + 3); graphics2D.drawLine(bottomLeft, whiteArea.getBottom() - 3, bottomRight, whiteArea.getBottom() - 3); } } // now we re-do the grouping of shapes into rows, this time with proper column breaks to avoid // rows that cross-over columns rows = this.groupShapesIntoRows(sourceImage, shapes, columnSeparators, true); this.addRowsToJochreImage(sourceImage, rows); this.findGuideLines(sourceImage); this.splitRows(sourceImage); if (this.splitAndJoin) { // figure out if the shapes contain a lot of "holes" // if they do, join them together // if they don't, try to split them int fillFactor = this.getFillFactor(sourceImage); if (fillFactor >= 2) { this.joinShapesHorizontally(sourceImage); } if (currentMonitor != null) { currentMonitor.setCurrentAction("imageMonitor.splittingShapes"); currentMonitor.setPercentComplete(0.4); } this.splitShapes(sourceImage, fillFactor); } //this.removeSpecks(sourceImage); this.joinShapesVertically(sourceImage); this.findGuideLines(sourceImage); this.combineRows(sourceImage); this.removeOrphans(sourceImage, false); if (currentMonitor != null) { currentMonitor.setCurrentAction("imageMonitor.groupingShapesIntoWords"); currentMonitor.setPercentComplete(0.6); } this.groupShapesIntoWords(sourceImage); this.removeOrphans(sourceImage, true); this.cleanMargins(sourceImage); if (currentMonitor != null) { currentMonitor.setCurrentAction("imageMonitor.analysingFontSize"); currentMonitor.setPercentComplete(0.7); } this.splitRowsByFontSize(sourceImage); if (currentMonitor != null) { currentMonitor.setCurrentAction("imageMonitor.groupingRowsIntoParagraphs"); currentMonitor.setPercentComplete(0.9); } this.groupRowsIntoParagraphs(sourceImage); sourceImage.setShapeCount(this.getShapeCount(sourceImage)); if (this.isDrawSegmentation()) { this.drawSegmentation(sourceImage); } if (currentMonitor != null) { currentMonitor.setFinished(true); } }
From source file:de.fhg.igd.swingrcp.SwingRCPUtilities.java
/** * Applies the given transparency mask to a buffered image. Always creates a * new buffered image containing an alpha channel. Copies the old image into * the new one and then sets the alpha pixels according to the given mask. * /* w w w .j av a2s . com*/ * @param img the old image * @param mask the alpha mask * @return the new image with alpha channel applied * @throws IllegalArgumentException if the image's size does not match the * mask's size */ public static BufferedImage applyTransparencyMask(BufferedImage img, ImageData mask) { if (mask.width != img.getWidth() || mask.height != img.getHeight()) { throw new IllegalArgumentException("Image size does not match the mask size"); } // copy image and also convert to RGBA BufferedImage result = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics g = result.getGraphics(); g.drawImage(img, 0, 0, null); WritableRaster alphaRaster = result.getAlphaRaster(); int alpha0[] = new int[] { 0 }; int alpha255[] = new int[] { 255 }; for (int y = 0; y < img.getHeight(); y++) { for (int x = 0; x < img.getWidth(); x++) { alphaRaster.setPixel(x, y, mask.getPixel(x, y) == 0 ? alpha0 : alpha255); } } return result; }
From source file:net.daimonin.client3d.editor.main.Editor3D.java
/** * Builds a single PNG out of all ImageSetImages, considering their calculated * coordinates.//from www.j a v a2 s. c o m * * @param fileNameImageSet Name of resulting PNG. * @param dimension [width, height] of the resulting PNG. where 0 is maximum * compression, 1 is no compression at all. * @throws IOException IOException. */ private static void writeImageSet(final String fileNameImageSet, final int[] dimension) throws IOException { BufferedImage bigImg = new BufferedImage(dimension[0], dimension[1], BufferedImage.TYPE_INT_ARGB); Graphics2D big = bigImg.createGraphics(); for (int i = 0; i < images.size(); i++) { if (images.get(i).getBorderSize() > 0) { ParameterBlock params = new ParameterBlock(); params.addSource(images.get(i).getImage()); params.add(images.get(i).getBorderSize()); // left pad params.add(images.get(i).getBorderSize()); // right pad params.add(images.get(i).getBorderSize()); // top pad params.add(images.get(i).getBorderSize()); // bottom pad params.add(new BorderExtenderConstant(new double[] { images.get(i).getBorderColor().getRed(), images.get(i).getBorderColor().getGreen(), images.get(i).getBorderColor().getBlue(), BORDERCOLORMAX })); big.drawImage(JAI.create("border", params).getAsBufferedImage(), images.get(i).getPosX(), images.get(i).getPosY(), null); } else { big.drawImage(images.get(i).getImage(), images.get(i).getPosX(), images.get(i).getPosY(), null); } } big.dispose(); ImageIO.write(bigImg, "png", new File(fileNameImageSet)); printInfo(System.getProperty("user.dir") + "/" + imageset + " created"); }