List of usage examples for java.awt.image BufferedImage setRGB
public void setRGB(int startX, int startY, int w, int h, int[] rgbArray, int offset, int scansize)
From source file:com.github.orangefoundry.gorender.controllers.ImageRenderController.java
private byte[] renderPlaceHolder(String size, String colour) throws IOException { if (size == null || size.isEmpty()) { size = Default.SIZE.getValue();//from www .j a v a 2 s. c om } if (colour == null || colour.isEmpty()) { colour = Default.COLOUR.getValue(); } String[] sizes = new String[2]; if (size != null && !size.isEmpty()) { sizes = size.toLowerCase().split("x"); } int width = Integer.parseInt(sizes[0]), height = Integer.parseInt(sizes[1]); final ColourToAWTColour colourToAWTColour = new ColourToAWTColour(); Color myColour = colourToAWTColour.getColour(colour); int rgb = myColour.getRGB(); BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); int[] data = new int[width * height]; int i = 0; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { data[i++] = rgb; } } bi.setRGB(0, 0, width, height, data, 0, width); ByteArrayOutputStream bao = new ByteArrayOutputStream(); ImageIO.write(bi, "png", bao); return bao.toByteArray(); }
From source file:pl.edu.icm.visnow.lib.utils.ImageUtilities.java
public static void copyRGBcolumns(BufferedImage sourceImg, int sourceStartX, int sourceWidth, BufferedImage targetImg, int targetStartX) { targetImg.setRGB(targetStartX, 0, sourceWidth, sourceImg.getHeight(), sourceImg.getRGB(sourceStartX, 0, sourceWidth, sourceImg.getHeight(), null, 0, sourceWidth), 0, sourceWidth);/*from w w w . java 2s. co m*/ }
From source file:pl.edu.icm.visnow.lib.utils.ImageUtilities.java
public static void copyRGB(BufferedImage sourceImg, int sourceStartX, int sourceStartY, int sourceWidth, int sourceHeight, BufferedImage targetImg, int targetStartX, int targetStartY) { targetImg.setRGB(targetStartX, targetStartY, sourceWidth, sourceHeight, sourceImg.getRGB(sourceStartX, sourceStartY, sourceWidth, sourceHeight, null, 0, sourceWidth), 0, sourceWidth);/* ww w . j a v a2 s .c o m*/ }
From source file:TextureByReference.java
public static void flipImage(BufferedImage bImage) { int width = bImage.getWidth(); int height = bImage.getHeight(); int[] rgbArray = new int[width * height]; bImage.getRGB(0, 0, width, height, rgbArray, 0, width); int[] tempArray = new int[width * height]; int y2 = 0;/*w w w. j av a 2 s . c om*/ for (int y = height - 1; y >= 0; y--) { for (int x = 0; x < width; x++) { tempArray[y2 * width + x] = rgbArray[y * width + x]; } y2++; } bImage.setRGB(0, 0, width, height, tempArray, 0, width); }
From source file:ImageOpByRomain.java
/** * <p>/*w ww. j av a 2 s . co m*/ * Writes a rectangular area of pixels in the destination * <code>BufferedImage</code>. Calling this method on an image of type * different from <code>BufferedImage.TYPE_INT_ARGB</code> and * <code>BufferedImage.TYPE_INT_RGB</code> will unmanage the image. * </p> * * @param img * the destination image * @param x * the x location at which to start storing pixels * @param y * the y location at which to start storing pixels * @param w * the width of the rectangle of pixels to store * @param h * the height of the rectangle of pixels to store * @param pixels * an array of pixels, stored as integers * @throws IllegalArgumentException * is <code>pixels</code> is non-null and of length < w*h */ public static void setPixels(BufferedImage img, int x, int y, int w, int h, int[] pixels) { if (pixels == null || w == 0 || h == 0) { return; } else if (pixels.length < w * h) { throw new IllegalArgumentException("pixels array must have a length" + " >= w*h"); } int imageType = img.getType(); if (imageType == BufferedImage.TYPE_INT_ARGB || imageType == BufferedImage.TYPE_INT_RGB) { WritableRaster raster = img.getRaster(); raster.setDataElements(x, y, w, h, pixels); } else { // Unmanages the image img.setRGB(x, y, w, h, pixels, 0, w); } }
From source file:org.opencastproject.composer.gstreamer.engine.GStreamerEncoderEngine.java
/** * Creates image out of gstreamer buffer. Buffer should have following properties: 32 bits/pixel and color depth of 24 * bits. Output image format is chosen based on the output file name. If width or height are equal or less than 0, * original image size is retained.//from w ww . java2 s . c om * * @param buffer * gstreamer buffer from which image will be constructed * @param width * width of the new image * @param height * height of the new image * @param output * output file name * @throws IOException * if writing image fails */ private void createImageOutOfBuffer(Buffer buffer, int width, int height, String output) throws IOException { // get buffer information Structure structure = buffer.getCaps().getStructure(0); int origHeight = structure.getInteger("height"); int origWidth = structure.getInteger("width"); // create original image IntBuffer intBuf = buffer.getByteBuffer().asIntBuffer(); int[] imageData = new int[intBuf.capacity()]; intBuf.get(imageData, 0, imageData.length); BufferedImage originalImage = new BufferedImage(origWidth, origHeight, BufferedImage.TYPE_INT_RGB); originalImage.setRGB(0, 0, origWidth, origHeight, imageData, 0, origWidth); BufferedImage image; if (height <= 0 || width <= 0) { logger.info("Retaining image of original size {}x{}", origWidth, origHeight); image = originalImage; } else { logger.info("Resizing image from {}x{} to {}x{}", new Object[] { origWidth, origHeight, width, height }); image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D graphics = image.createGraphics(); graphics.setRenderingHints(imageRenderingHints); graphics.drawImage(originalImage, 0, 0, width, height, null); graphics.dispose(); } // write image File outputFile = new File(output); ImageIO.write(image, FilenameUtils.getExtension(output), outputFile); }
From source file:org.pentaho.reporting.libraries.base.util.ResourceBundleSupport.java
/** * Creates a transparent image. These can be used for aligning menu items. * * @param width the width.// w w w .j ava 2 s . c o m * @param height the height. * @return the created transparent image. */ private BufferedImage createTransparentImage(final int width, final int height) { final BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); final int[] data = img.getRGB(0, 0, width, height, null, 0, width); img.setRGB(0, 0, width, height, data, 0, width); return img; }
From source file:com.neophob.sematrix.core.glue.Collector.java
private void saveImage(Visual v, String filename, int[] data) { try {//from w w w. j a v a 2 s . c o m int w = v.getGenerator1().getInternalBufferXSize(); int h = v.getGenerator1().getInternalBufferYSize(); BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); bi.setRGB(0, 0, w, h, data, 0, w); File outputfile = new File(filename); ImageIO.write(bi, "png", outputfile); } catch (IOException e) { LOG.log(Level.SEVERE, "Failed to save screenshot " + filename, e); } }
From source file:com.googlecode.libautocaptcha.tools.VodafoneItalyTool.java
private java.awt.Image convertImage(net.sourceforge.javaocr.Image image) { final int W = image.getWidth(); final int H = image.getHeight(); BufferedImage result = new BufferedImage(W, H, BufferedImage.TYPE_INT_RGB); AwtImage temp = new AwtImage(result); image.copy(temp);//w w w. j a v a2s . c o m result.setRGB(0, 0, W, H, temp.pixels, 0, W); return result; }
From source file:RasterTest.java
public void updateRenderRaster() { // takes the Depth Raster and updates the Render Raster // containing the image based on the depth values stored in // the Depth Raster. // create a temporary BufferedImage for the depth components BufferedImage tempBufferedImage = new BufferedImage(m_DepthRaster.getDepthComponent().getWidth(), m_DepthRaster.getDepthComponent().getHeight(), BufferedImage.TYPE_INT_RGB); // allocate an array of ints to store the depth components from the // Depth Raster if (m_DepthData == null) m_DepthData = new int[m_DepthRaster.getDepthComponent().getWidth() * m_DepthRaster.getDepthComponent().getHeight()]; // copy the depth values from the Raster into the int array ((DepthComponentInt) m_DepthRaster.getDepthComponent()).getDepthData(m_DepthData); // assign the depth values to the temporary image, the integer depths // will be//from ww w .j ava2s. c om // interpreted as integer rgb values. tempBufferedImage.setRGB(0, 0, m_DepthRaster.getDepthComponent().getWidth(), m_DepthRaster.getDepthComponent().getHeight(), m_DepthData, 0, m_DepthRaster.getDepthComponent().getWidth()); // get a graphics device for the image Graphics g = tempBufferedImage.getGraphics(); Dimension size = new Dimension(); m_RenderRaster.getSize(size); // because the Depth Raster is a different size to the Render Raster, // i.e. the Depth Raster is canvas width by canvas height and the Render // Raster // is of aritrary size, we rescale the image here. g.drawImage(tempBufferedImage, 0, 0, (int) size.getWidth(), (int) size.getHeight(), null); // finally, assign the scaled image to the RenderRaster m_RenderRaster.setImage(new ImageComponent2D(BufferedImage.TYPE_INT_RGB, tempBufferedImage)); }