List of usage examples for java.awt.image BufferedImage TYPE_INT_RGB
int TYPE_INT_RGB
To view the source code for java.awt.image BufferedImage TYPE_INT_RGB.
Click Source Link
From source file:eu.europa.esig.dss.pades.signature.visible.ImageFactory.java
private static InputStream convertToInputStream(BufferedImage buffImage, int dpi) throws IOException { Iterator<ImageWriter> it = ImageIO.getImageWritersByFormatName("jpeg"); if (!it.hasNext()) { throw new DSSException("No writer for JPEG found"); }/*w w w . j ava2 s. c om*/ ImageWriter writer = it.next(); JPEGImageWriteParam jpegParams = (JPEGImageWriteParam) writer.getDefaultWriteParam(); jpegParams.setCompressionMode(JPEGImageWriteParam.MODE_EXPLICIT); jpegParams.setCompressionQuality(1); ImageTypeSpecifier typeSpecifier = ImageTypeSpecifier .createFromBufferedImageType(BufferedImage.TYPE_INT_RGB); IIOMetadata metadata = writer.getDefaultImageMetadata(typeSpecifier, jpegParams); initDpi(metadata, dpi); ByteArrayOutputStream os = new ByteArrayOutputStream(); ImageOutputStream imageOs = ImageIO.createImageOutputStream(os); writer.setOutput(imageOs); writer.write(metadata, new IIOImage(buffImage, null, metadata), jpegParams); InputStream is = new ByteArrayInputStream(os.toByteArray()); return is; }
From source file:SaveImage.java
public void filterImage() { BufferedImageOp op = null;/*from w w w . ja v a 2 s .c o m*/ if (opIndex == lastOp) { return; } lastOp = opIndex; switch (opIndex) { case 0: biFiltered = bi; /* original */ return; case 1: /* low pass filter */ case 2: /* sharpen */ float[] data = (opIndex == 1) ? BLUR3x3 : SHARPEN3x3; op = new ConvolveOp(new Kernel(3, 3, data), ConvolveOp.EDGE_NO_OP, null); break; case 3: /* lookup */ byte lut[] = new byte[256]; for (int j = 0; j < 256; j++) { lut[j] = (byte) (256 - j); } ByteLookupTable blut = new ByteLookupTable(0, lut); op = new LookupOp(blut, null); break; } /* * Rather than directly drawing the filtered image to the destination, * filter it into a new image first, then that filtered image is ready for * writing out or painting. */ biFiltered = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); op.filter(bi, biFiltered); }
From source file:ch.rasc.downloadchart.DownloadChartServlet.java
private static void handleJpg(HttpServletResponse response, byte[] imageData, Integer width, Integer height, String filename, JpegOptions options) throws IOException { response.setContentType("image/jpeg"); response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + ".jpg\";"); BufferedImage image = ImageIO.read(new ByteArrayInputStream(imageData)); Dimension newDimension = calculateDimension(image, width, height); int imgWidth = image.getWidth(); int imgHeight = image.getHeight(); if (newDimension != null) { imgWidth = newDimension.width;/* ww w . ja v a 2 s . co m*/ imgHeight = newDimension.height; } BufferedImage newImage = new BufferedImage(imgWidth, imgHeight, BufferedImage.TYPE_INT_RGB); Graphics2D g = newImage.createGraphics(); g.drawImage(image, 0, 0, imgWidth, imgHeight, Color.BLACK, null); g.dispose(); if (newDimension != null) { 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); } try (ImageOutputStream ios = ImageIO.createImageOutputStream(response.getOutputStream())) { Iterator<ImageWriter> iter = ImageIO.getImageWritersByFormatName("jpg"); ImageWriter writer = iter.next(); ImageWriteParam iwp = writer.getDefaultWriteParam(); iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); if (options != null && options.quality != null && options.quality != 0 && options.quality != 100) { iwp.setCompressionQuality(options.quality / 100f); } else { iwp.setCompressionQuality(1); } writer.setOutput(ios); writer.write(null, new IIOImage(newImage, null, null), iwp); writer.dispose(); } }
From source file:com.googlecode.fightinglayoutbugs.helpers.ImageHelper.java
public static BufferedImage pixelsToImage(boolean[][] pixels) { if (pixels == null) { return null; }/*from w w w .j a v a 2s. c o m*/ int w = pixels.length; if (w > 0) { int h = pixels[0].length; if (h > 0) { BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); for (int x = 0; x < w; ++x) { boolean[] column = pixels[x]; for (int y = 0; y < h; ++y) { image.setRGB(x, y, column[y] ? 0 : 0xFFFFFF); } } return image; } else { throw new IllegalArgumentException("pixels[0].length must not be 0."); } } else { throw new IllegalArgumentException("pixels.length must not be 0."); } }
From source file:AffineTransformApp.java
public void createBufferedImages() { biSrc = new BufferedImage(displayImage.getWidth(this), displayImage.getHeight(this), BufferedImage.TYPE_INT_RGB); big = biSrc.createGraphics();/* w ww . j a v a 2 s.c om*/ big.drawImage(displayImage, 0, 0, this); bi = biSrc; biDest = new BufferedImage(displayImage.getWidth(this), displayImage.getHeight(this), BufferedImage.TYPE_INT_RGB); }
From source file:org.n52.io.type.quantity.handler.img.ChartIoHandler.java
private BufferedImage createImage() { IoParameters parameters = getParameters(); int width = parameters.getWidth(); int height = parameters.getHeight(); BufferedImage chartImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D chartGraphics = chartImage.createGraphics(); chartGraphics.fillRect(0, 0, width, height); chartGraphics.setColor(Color.WHITE); jFreeChart.setTextAntiAlias(true);//from ww w . j a v a2 s. com jFreeChart.setAntiAlias(true); if (jFreeChart.getLegend() != null) { jFreeChart.getLegend().setFrame(BlockBorder.NONE); } jFreeChart.draw(chartGraphics, new Rectangle2D.Float(0, 0, width, height)); return chartImage; }
From source file:org.n52.oxf.render.sos.TimeSeriesMapChartRenderer.java
/** * @param observationCollection/* ww w . ja v a 2 s . c o m*/ * @param screenW * @param screenH * @param bbox * @param selectedFeatures * the Features of Interest for which a chart shall be renderered. */ public StaticVisualization renderLayer(OXFFeatureCollection observationCollection, ParameterContainer paramCon, int screenW, int screenH, IBoundingBox bbox, Set<OXFFeature> selectedFeatures) { if (selectedFeaturesCache == null) { selectedFeaturesCache = selectedFeatures; } // before starting to render --> run garbageCollection Runtime.getRuntime().gc(); LOGGER.info("Garbage Collection done."); // -- String[] observedProperties; // which observedProperty has been used?: ParameterShell observedPropertyPS = paramCon.getParameterShellWithServiceSidedName("observedProperty"); if (observedPropertyPS.hasMultipleSpecifiedValues()) { observedProperties = observedPropertyPS.getSpecifiedTypedValueArray(String[].class); } else if (observedPropertyPS.hasSingleSpecifiedValue()) { observedProperties = new String[] { (String) observedPropertyPS.getSpecifiedValue() }; } else { throw new IllegalArgumentException("no observedProperties found."); } // find tuples: if (obsValues4FOI == null) { obsValues4FOI = new ObservationSeriesCollection(observationCollection, selectedFeaturesCache, observedProperties, true); } ContextBoundingBox contextBBox = new ContextBoundingBox(bbox); BufferedImage image = new BufferedImage(screenW, screenH, BufferedImage.TYPE_INT_RGB); Graphics2D g = image.createGraphics(); // draw white background: g.setColor(Color.WHITE); g.fillRect(0, 0, screenW, screenH); g.setColor(Color.BLACK); for (OXFFeature chartFeature : selectedFeaturesCache) { // // CACHING: create Plot for each "chart feature" and add it to the cache: // if (!chartCache.containsKey(chartFeature)) { Map<ITimePosition, ObservedValueTuple> timeMap = obsValues4FOI.getAllTuples(chartFeature); // draw a chart if there are tuples for the chartFeature available: if (timeMap != null) { XYPlot chart = drawChart4FOI(chartFeature.getID(), timeMap); chartCache.put(chartFeature, chart); } } // // draw the plots (which are in the cache): // Point pRealWorld = (Point) chartFeature.getGeometry(); java.awt.Point pScreen = ContextBoundingBox.realworld2Screen(contextBBox.getActualBBox(), screenW, screenH, new Point2D.Double(pRealWorld.getCoordinate().x, pRealWorld.getCoordinate().y)); XYPlot cachedPlot = (XYPlot) chartCache.get(chartFeature); // if there is a plot in the cache for the chartFeature -> draw it: if (cachedPlot != null) { cachedPlot.getRangeAxis().setRange((Double) obsValues4FOI.getMinimum(0), (Double) obsValues4FOI.getMaximum(0)); cachedPlot.draw(g, new Rectangle2D.Float(pScreen.x + X_SHIFT, pScreen.y + Y_SHIFT, CHART_WIDTH, CHART_HEIGHT), null, null, null); } else { g.drawString("No data available", pScreen.x + X_SHIFT, pScreen.y + Y_SHIFT); } // draw point of feature: g.fillOval(pScreen.x - (FeatureGeometryRenderer.DOT_SIZE_POINT / 2), pScreen.y - (FeatureGeometryRenderer.DOT_SIZE_POINT / 2), FeatureGeometryRenderer.DOT_SIZE_POINT, FeatureGeometryRenderer.DOT_SIZE_POINT); } return new StaticVisualization(image); }
From source file:ScreenCapture.java
public boolean crop() { if (startPoint.equals(endPoint)) return true; boolean succeeded = true; int x1 = (startPoint.x < endPoint.x) ? startPoint.x : endPoint.x; int y1 = (startPoint.y < endPoint.y) ? startPoint.y : endPoint.y; int x2 = (startPoint.x > endPoint.x) ? startPoint.x : endPoint.x; int y2 = (startPoint.y > endPoint.y) ? startPoint.y : endPoint.y; int width = (x2 - x1) + 1; int height = (y2 - y1) + 1; BufferedImage biCrop = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D g2d = biCrop.createGraphics(); BufferedImage bi = (BufferedImage) image; BufferedImage bi2 = bi.getSubimage(x1, y1, width, height); g2d.drawImage(bi2, null, 0, 0);//w ww. j av a2 s .c o m g2d.dispose(); if (succeeded) setImage(biCrop); else { startPoint.x = endPoint.x; startPoint.y = endPoint.y; repaint(); } return succeeded; }
From source file:de.uni_siegen.wineme.come_in.thumbnailer.thumbnailers.PDFBoxThumbnailer.java
@SuppressWarnings("unchecked") @Override//w ww .j a v a 2 s. c om public void generateThumbnails(final File input, final File outputFolder) throws IOException, ThumbnailerException { PDDocument document = null; try { try { document = PDDocument.load(input); } catch (final IOException e) { throw new ThumbnailerException("Could not load PDF File", e); } final List<PDPage> allPages = document.getDocumentCatalog().getAllPages(); int pageNumber = 0; for (final PDPage page : allPages) { final BufferedImage image = this.writeImageForPage(document, page, BufferedImage.TYPE_INT_RGB); final File outputFile = ThumbnailNamer.getFile(outputFolder, pageNumber); if (image.getWidth() == this.thumbWidth) { ImageIO.write(image, PDFBoxThumbnailer.OUTPUT_FORMAT, outputFile); } else { final ResizeImage resizer = new ResizeImage(this.thumbWidth, this.thumbHeight); resizer.resizeMethod = ResizeImage.RESIZE_FIT_BOTH_DIMENSIONS; resizer.setInputImage(image); resizer.writeOutput(outputFile); } pageNumber++; } } finally { if (document != null) { try { document.close(); } catch (final IOException e) { // swallow exception on closing. } } } }
From source file:com.jaeksoft.searchlib.util.ImageUtils.java
public final static BufferedImage reduceImage(BufferedImage image, int width, int height) { int type = (image.getTransparency() == Transparency.OPAQUE) ? BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB; BufferedImage ret = (BufferedImage) image; int w = image.getWidth(); int h = image.getHeight(); while (w != width || h != height) { if (w > width) { w /= 2;//from w w w . j av a 2 s . c om if (w < width) w = width; } if (h > height) { h /= 2; if (h < height) h = height; } BufferedImage tmp = new BufferedImage(w, h, type); 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; } return ret; }