List of usage examples for java.awt.image BufferedImage BufferedImage
public BufferedImage(int width, int height, int imageType)
From source file:at.tuwien.ifs.somtoolbox.visualization.ClusterConnectionsVisualizer.java
@Override public BufferedImage createVisualization(int variantIndex, GrowingSOM gsom, int width, int height) throws SOMToolboxException { GrowingLayer layer = gsom.getLayer(); BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D g = image.createGraphics(); g.setBackground(Color.WHITE); g.clearRect(0, 0, width, height);/*www . j av a 2 s. c om*/ // need to calculate some params relative to the unit width/height, which is relative to the desired output size // a unitWidth/Height of 10, as used previously, works by default only fine in the SOMViewer int somWidth = layer.getXSize(); int somHeight = layer.getYSize(); double unitWidth = width / somWidth; double unitHeight = height / somHeight; DoubleMatrix2D unitDistanceMatrix = gsom.getLayer().getUnitDistanceMatrix(); for (int col = 0; col < somWidth; col++) { for (int row = 0; row < somHeight; row++) { if (col < somWidth - 1) { // draw horizontal connection double distanceRight = unitDistanceMatrix.get(layer.getUnitIndex(col, row), layer.getUnitIndex(col + 1, row)); g.setPaint(getColor(distanceRight)); int xPos = (int) (col * unitHeight + unitHeight * 0.7); int yPos = (int) (row * unitWidth + unitWidth * 0.4); g.fillRect(xPos, yPos, (int) (unitWidth * 0.6), (int) (unitHeight * 0.2)); } if (row < somHeight - 1) { // draw vertical connection double distanceLower = unitDistanceMatrix.get(layer.getUnitIndex(col, row), layer.getUnitIndex(col, row + 1)); g.setPaint(getColor(distanceLower)); int xPos = (int) (col * unitHeight + unitHeight * 0.4); int yPos = (int) (row * unitWidth + unitWidth * 0.7); g.fillRect(xPos, yPos, (int) (unitWidth * 0.2), (int) (unitHeight * 0.6)); } } } return image; }
From source file:com.uwsoft.editor.proxy.ResolutionManager.java
public static BufferedImage imageResize(File file, float ratio) { BufferedImage destinationBufferedImage = null; try {//w ww .ja v a 2 s . c o m BufferedImage sourceBufferedImage = ImageIO.read(file); if (ratio == 1.0) { return sourceBufferedImage; } // When image has to be resized smaller then 3 pixels we should leave it as is, as to ResampleOP limitations // But it should also trigger a warning dialog at the and of the import, to notify the user of non resized images. if (sourceBufferedImage.getWidth() * ratio < 3 || sourceBufferedImage.getHeight() * ratio < 3) { return null; } int newWidth = Math.max(3, Math.round(sourceBufferedImage.getWidth() * ratio)); int newHeight = Math.max(3, Math.round(sourceBufferedImage.getHeight() * ratio)); String name = file.getName(); Integer[] patches = null; if (name.endsWith(EXTENSION_9PATCH)) { patches = NinePatchUtils.findPatches(sourceBufferedImage); sourceBufferedImage = NinePatchUtils.removePatches(sourceBufferedImage); newWidth = Math.round(sourceBufferedImage.getWidth() * ratio); newHeight = Math.round(sourceBufferedImage.getHeight() * ratio); System.out.println(sourceBufferedImage.getWidth()); destinationBufferedImage = new BufferedImage(newWidth, newHeight, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = destinationBufferedImage.createGraphics(); g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR); g2.drawImage(sourceBufferedImage, 0, 0, newWidth, newHeight, null); g2.dispose(); } else { // resize with bilinear filter ResampleOp resampleOp = new ResampleOp(newWidth, newHeight); destinationBufferedImage = resampleOp.filter(sourceBufferedImage, null); } if (patches != null) { destinationBufferedImage = NinePatchUtils.convertTo9Patch(destinationBufferedImage, patches, ratio); } } catch (IOException ignored) { } return destinationBufferedImage; }
From source file:ConvertUtil.java
/** * Converts the source image to 24-bit colour (RGB). No transparency. * /* ww w. java 2s. c o m*/ * @param src * the source image to convert * @return a copy of the source image with a 24-bit colour depth */ public static BufferedImage convert24(BufferedImage src) { BufferedImage dest = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TYPE_INT_RGB); ColorConvertOp cco = new ColorConvertOp(src.getColorModel().getColorSpace(), dest.getColorModel().getColorSpace(), null); cco.filter(src, dest); return dest; }
From source file:com.t3.image.ImageUtil.java
public static BufferedImage createCompatibleImage(int width, int height, int transparency) { return new BufferedImage(width, height, transparency); }
From source file:de.darkblue.bongloader2.utils.ToolBox.java
public static BufferedImage resizeImage(BufferedImage image, int width, int height) { BufferedImage returnValue = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g2D = returnValue.createGraphics(); g2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); AffineTransform at = AffineTransform.getScaleInstance((double) width / image.getWidth(), (double) height / image.getHeight()); g2D.drawRenderedImage(image, at);/*from ww w . j a v a2 s .co m*/ return returnValue; }
From source file:peakml.graphics.JFreeChartTools.java
/** * This method writes the given graph to the output stream in the PNG format. * // w w w.j a v a 2 s . c om * @param out The output stream to write to. * @param chart The chart to be written. * @param width The width of the image. * @param height The height of the image. * @throws IOException Thrown when an error occurs with the IO. */ public static void writeAsPNG(OutputStream out, JFreeChart chart, int width, int height) throws IOException { BufferedImage graph_img = new BufferedImage(800, 500, BufferedImage.TYPE_INT_ARGB); chart.draw(graph_img.createGraphics(), new java.awt.Rectangle(0, 0, 800, 500)); javax.imageio.ImageIO.write(graph_img, "png", out); }
From source file:com.seleniumtests.util.imaging.ImageProcessor.java
/** * Agregate 2 pictures/*from w w w . ja v a2 s .c o m*/ * @param imgf1 first picture to agregate * @param imgf2 seconde picture to aggregate * @param img2PosX X coord where second picture will be but, relative to first one * @param img2PosY Y coord where second picture will be but, relative to first one * @return the complete picture */ public static BufferedImage concat(BufferedImage img1, BufferedImage img2, Integer img2PosX, Integer img2PosY) { if (img2PosX < 0 || img2PosY < 0) { throw new IllegalArgumentException("relative position must be > 0"); } Integer finalWidth = Math.max(img2.getWidth() + img2PosX, img1.getWidth()); Integer finalHeight = Math.max(img2.getHeight() + img2PosY, img1.getHeight()); BufferedImage img = new BufferedImage(finalWidth, finalHeight, BufferedImage.TYPE_INT_RGB); img.createGraphics().drawImage(img1, 0, 0, null); img.createGraphics().drawImage(img2, img2PosX, img2PosY, null); return img; }
From source file:D20140128.ApacheXMLGraphicsTest.TilingPatternExample.java
private void generatePNGusingJava2D(File outputFile) throws IOException { BufferedImage image = new BufferedImage(400, 200, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = image.createGraphics(); paintTileAlone(g2d);/* w w w. ja v a 2 s.co m*/ paintShapes(g2d); paintText(g2d); g2d.dispose(); ImageWriterUtil.saveAsPNG(image, outputFile); }
From source file:MultiTextureTest.java
public Texture createLightMap() { int width = 128; int height = 128; BufferedImage bimage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); int[] rgbArray = new int[width * height]; int index, index2; int rgbInc = 256 / (width / 2 - 20); int rgbValue = 0; int k = width / 2 - 5; int i, j, rgb; rgb = 0xff;//from w w w.ja va2 s . c o m rgbValue = rgb | (rgb << 8) | (rgb << 16) | (rgb << 24); for (i = width / 2 - 1, j = 0; j < 10; j++, i--) { rgbArray[i] = rgbValue; } for (; i > 8; i--, rgb -= rgbInc) { rgbValue = rgb | (rgb << 8) | (rgb << 16) | (rgb << 24); rgbArray[i] = rgbValue; } for (; i >= 0; i--) { rgbArray[i] = rgbValue; } for (i = 0; i < width / 2; i++) { rgbValue = rgbArray[i]; index = i; index2 = (width - i - 1); for (j = 0; j < height; j++) { rgbArray[index] = rgbArray[index2] = rgbValue; index += width; index2 += width; } } bimage.setRGB(0, 0, width, height, rgbArray, 0, width); ImageComponent2D grayImage = new ImageComponent2D(ImageComponent.FORMAT_RGB, bimage); lightTex = new Texture2D(Texture.BASE_LEVEL, Texture.RGB, width, height); lightTex.setImage(0, grayImage); return lightTex; }
From source file:net.sf.jabref.gui.PdfPreviewPanel.java
private BufferedImage resizeImage(BufferedImage originalImage, int width, int height, int type) { int h = originalImage.getHeight(); int w = originalImage.getWidth(); if ((height == 0) || (width == 0)) { height = h;//from w w w . j ava2 s. c o m width = w; } else { float factorH = (float) height / (float) h; float factorW = (float) width / (float) w; if (factorH < factorW) { // use factorH, only width has to be changed as height is // already correct width = Math.round(w * factorH); } else { width = Math.round(h * factorW); } } BufferedImage resizedImage = new BufferedImage(width, height, type); Graphics2D g = resizedImage.createGraphics(); g.drawImage(originalImage, 0, 0, width, height, null); return resizedImage; }