List of usage examples for java.awt.image BufferedImage BufferedImage
public BufferedImage(int width, int height, int imageType)
From source file:Main.java
public GradientImage(int width, int height, Color[] colors, int alignment) { image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); pixels = ((DataBufferInt) image.getRaster().getDataBuffer()).getData(); this.alignment = alignment; this.width = width; this.height = height; this.colors = colors; rgbs = new int[colors.length]; for (int i = 0; i < rgbs.length; i++) { rgbs[i] = colors[i].getRGB();/* w w w . j a v a 2s . c o m*/ } try { renderImage(); } catch (Exception error) { error.printStackTrace(); } }
From source file:gr.iti.mklab.reveal.forensics.util.Util.java
public static BufferedImage getBufferedIm(int[][][] rgbValues) { int ImW = rgbValues[0].length; int ImH = rgbValues[0][0].length; BufferedImage ImageOut = new BufferedImage(ImW, ImH, 5); // 5 for PNG; Color tmpColor;//from ww w . j a v a2s. co m for (int ii = 0; ii < ImW; ii++) { for (int jj = 0; jj < ImH; jj++) { tmpColor = new Color((int) Math.round(rgbValues[0][ii][jj]), (int) Math.round(rgbValues[1][ii][jj]), (int) Math.round(rgbValues[2][ii][jj])); ImageOut.setRGB(ii, jj, tmpColor.getRGB()); } } return ImageOut; }
From source file:com.o2d.pkayjava.editor.proxy.ResolutionManager.java
public static BufferedImage imageResize(File file, float ratio) { BufferedImage destinationBufferedImage = null; try {/*from w w w.j ava2 s . c o m*/ BufferedImage sourceBufferedImage = ImageIO.read(file); if (ratio == 1.0) { return null; } // 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:com.joliciel.jochre.search.highlight.ImageSnippet.java
public BufferedImage getImage() { try {/* www. j a v a 2 s .c o m*/ BufferedImage originalImage = ImageIO.read(imageFile); BufferedImage imageSnippet = new BufferedImage(this.rectangle.getWidth(), this.rectangle.getHeight(), BufferedImage.TYPE_INT_ARGB); originalImage = originalImage.getSubimage(this.rectangle.getLeft(), this.rectangle.getTop(), this.rectangle.getWidth(), this.rectangle.getHeight()); Graphics2D graphics2D = imageSnippet.createGraphics(); graphics2D.drawImage(originalImage, 0, 0, this.rectangle.getWidth(), this.rectangle.getHeight(), null); int extra = 2; for (Rectangle rect : this.highlights) { graphics2D.setStroke(new BasicStroke(1)); graphics2D.setPaint(Color.BLACK); graphics2D.drawRect(rect.getLeft() - this.rectangle.getLeft() - extra, rect.getTop() - this.rectangle.getTop() - extra, rect.getWidth() + (extra * 2), rect.getHeight() + (extra * 2)); graphics2D.setColor(new Color(255, 255, 0, 127)); graphics2D.fillRect(rect.getLeft() - this.rectangle.getLeft() - extra, rect.getTop() - this.rectangle.getTop() - extra, rect.getWidth() + (extra * 2), rect.getHeight() + (extra * 2)); } return imageSnippet; } catch (IOException e) { LogUtils.logError(LOG, e); throw new RuntimeException(e); } }
From source file:TexturedText.java
/** Construct the object */ public TexturedText() { super();/*from w w w . j ava2 s. c o m*/ setBackground(Color.white); int width = 8, height = 8; bim = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = bim.createGraphics(); for (int i = 0; i < width; i++) { g2.setPaint(colors[(i / 2) % colors.length]); g2.drawLine(0, i, i, 0); g2.drawLine(width - i, height, width, height - i); } Rectangle r = new Rectangle(0, 0, bim.getWidth(), bim.getHeight()); tp = new TexturePaint(bim, r); }
From source file:fi.helsinki.opintoni.service.ImageService.java
private BufferedImage toJpg(BufferedImage bufferedImage) { BufferedImage jpgImage = new BufferedImage(bufferedImage.getWidth(), bufferedImage.getHeight(), BufferedImage.TYPE_INT_RGB); jpgImage.createGraphics().drawImage(bufferedImage, 0, 0, Color.BLACK, null); return jpgImage; }
From source file:image.writer.ImageWriterExample1.java
/** * Creates a bitmap file. We paint a few things on a bitmap and then save the bitmap using * an ImageWriter./*from w w w. ja v a 2 s . co m*/ * @param outputFile the target file * @param format the target format (a MIME type, ex. "image/png") * @throws IOException In case of an I/O error */ public void generateBitmapUsingJava2D(File outputFile, String format) throws IOException { //String compression = "CCITT T.6"; String compression = "PackBits"; boolean monochrome = compression.startsWith("CCITT"); //CCITT is for 1bit b/w only BufferedImage bimg; if (monochrome) { bimg = new BufferedImage(400, 200, BufferedImage.TYPE_BYTE_BINARY); } else { bimg = new BufferedImage(400, 200, BufferedImage.TYPE_INT_RGB); } Graphics2D g2d = bimg.createGraphics(); g2d.setBackground(Color.white); g2d.clearRect(0, 0, 400, 200); g2d.setColor(Color.black); //Paint something paintSome(g2d, 1); OutputStream out = new java.io.FileOutputStream(outputFile); out = new java.io.BufferedOutputStream(out); try { ImageWriter writer = ImageWriterRegistry.getInstance().getWriterFor(format); ImageWriterParams params = new ImageWriterParams(); params.setCompressionMethod(compression); params.setResolution(72); writer.writeImage(bimg, out, params); } finally { IOUtils.closeQuietly(out); } }
From source file:doge.photo.DogePhotoManipulator.java
private BufferedImage manipulate(BufferedImage sourceImage) { double aspectRatio = sourceImage.getHeight() / (double) sourceImage.getWidth(); int height = (int) Math.floor(IMAGE_WIDTH * aspectRatio); BufferedImage destinationImage = new BufferedImage(IMAGE_WIDTH, height, BufferedImage.TYPE_INT_RGB); render(sourceImage, destinationImage); return destinationImage; }
From source file:PrintFromButton.java
public void init() { setLayout(new BorderLayout()); GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); BufferedImage bImage = new BufferedImage(200, 200, BufferedImage.TYPE_INT_ARGB); ImageComponent2D buffer = new ImageComponent2D(ImageComponent.FORMAT_RGBA, bImage); buffer.setCapability(ImageComponent2D.ALLOW_IMAGE_READ); Raster drawRaster = new Raster(new Point3f(0.0f, 0.0f, 0.0f), Raster.RASTER_COLOR, 0, 0, 200, 200, buffer, null);// ww w . j av a2s . c om drawRaster.setCapability(Raster.ALLOW_IMAGE_WRITE); // create the main scene graph BranchGroup scene = createSceneGraph(drawRaster); // create the on-screen canvas Canvas3D d = new Canvas3D(config, false); add("Center", d); // create a simple universe u = new SimpleUniverse(d); // This will move the ViewPlatform back a bit so the // objects in the scene can be viewed. u.getViewingPlatform().setNominalViewingTransform(); // create an off Screen Buffer c = new OffScreenCanvas3D(config, true, drawRaster); // set the offscreen to match the onscreen Screen3D sOn = d.getScreen3D(); Screen3D sOff = c.getScreen3D(); sOff.setSize(sOn.getSize()); sOff.setPhysicalScreenWidth(sOn.getPhysicalScreenWidth()); sOff.setPhysicalScreenHeight(sOn.getPhysicalScreenHeight()); // attach the same view to the offscreen canvas u.getViewer().getView().addCanvas3D(c); // create the gui Button b = new Button("Print"); b.addActionListener(this); Panel p = new Panel(); p.add(b); add("North", p); u.addBranchGraph(scene); }
From source file:com.gargoylesoftware.htmlunit.javascript.host.canvas.CanvasRenderingContext2D.java
/** * Constructs in association with {@link HTMLCanvasElement}. * @param canvas the {@link HTMLCanvasElement} *//*from w w w . java2 s . c om*/ public CanvasRenderingContext2D(final HTMLCanvasElement canvas) { canvas_ = canvas; image_ = new BufferedImage(canvas.getWidth(), canvas.getHeight(), BufferedImage.TYPE_INT_RGB); graphics2D_ = image_.createGraphics(); }