To image buffered image.

@param component the component
@return the buffered image
6490
public static BufferedImage toImage(@javax.annotation.Nonnull final Component component) {
    try {
      com.simiacryptus.util.Util.layout(component);
      @javax.annotation.Nonnull final BufferedImage img = new BufferedImage(component.getWidth(), component.getHeight(), BufferedImage.TYPE_INT_ARGB_PRE);
      final Graphics2D g = img.createGraphics();
      g.setColor(component.getForeground());
      g.setFont(component.getFont());
      component.print(g);
      return img;
    } catch (@javax.annotation.Nonnull final Exception e) {
      return null;
    }
  }
1248036
private static Map decodeComponent(String component) {
        byte[] bodyData = Base64.decode(component, Base64.DEFAULT);
        if (bodyData == null)
            return null;
        try {
            return Manager.getObjectMapper().readValue(bodyData, Map.class);
        } catch (IOException e) {
            Log.w(TAG, "Failed decode component: %s", e, component);
            return null;
        }
    }
864266
public BufferedImage getBufferedImage(int width, int height) {
		BufferedImage bi = chart.createBufferedImage(width, height);
		return bi;
	}
277392
@Nullable
  public static BufferedImage resize(@Nullable final BufferedImage image) {
    if (null == image) return image;
    final int width = Math.min(image.getWidth(), 800);
    if (width == image.getWidth()) return image;
    final int height = image.getHeight() * width / image.getWidth();
    @javax.annotation.Nonnull final BufferedImage rerender = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    final Graphics gfx = rerender.getGraphics();
    @javax.annotation.Nonnull final RenderingHints hints = new RenderingHints(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    ((Graphics2D) gfx).setRenderingHints(hints);
    gfx.drawImage(image, 0, 0, rerender.getWidth(), rerender.getHeight(), null);
    return rerender;
  }
179206
@Override
	public void getImageBytes(ByteBuffer buffer) {
		final BufferedImage bi = getImage();
		if (bi != null) {
			buffer.put(ImageUtils.imageToBytes(bi));
		}
	}
272738
public void setBufferedImage(BufferedImage img) {
        image = img;
        width = img.getWidth();
        height = img.getHeight();
        updateColorArray();
    }
1274809
public static BufferedImage flipHorizontal(BufferedImage image)
    {
        final int width = image.getWidth();
        final int height = image.getHeight();
        final BufferedImage flipped = createImage(width, height, image.getColorModel().getTransparency());
        final Graphics2D g = flipped.createGraphics();

        optimizeGraphicsSpeed(g);
        g.drawImage(image, 0, 0, width, height, width, 0, 0, height, null);
        g.dispose();

        return flipped;
    }
1337010
public static byte[] bufferedImageToBMPByteArray(BufferedImage image, BufferedImage bufferedImage) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        try {
            /* ImageTypeSpecifier type =
             ImageTypeSpecifier.createFromRenderedImage(image);
             Iterator<ImageWriter> iter = ImageIO.getImageWriters(type, "bmp");
             System.err.println(ImageIO.getWriterFormatNames());
             boolean sig=iter.hasNext();*/
            //BufferedImage bufferedImage = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_RGB);
            Graphics2D ngraphics = (Graphics2D) bufferedImage.getGraphics();
            /*ngraphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
             RenderingHints.VALUE_INTERPOLATION_BILINEAR);*/
            //ngraphics.drawImage(image, 0, 0,512,384,0,0,image.getWidth(),image.getHeight(), null);        	
            //ngraphics.drawImage(image.getScaledInstance(200, 300, BufferedImage.SCALE_FAST), 0, 0,null);        	
            ngraphics.drawImage(image, 0, 0, null);
            ImageIO.write(bufferedImage, "bmp", baos);
            baos.flush();
            byte[] imageInByte = baos.toByteArray();
            baos.close();
            return imageInByte;
        } catch (IOException ex) {
            Logger.getLogger(PHATImageUtils.class.getName()).log(Level.SEVERE, "bufferedImageToByteArray", ex);
        }
        return null;
    }
1135895
public static int getGraphicsDeviceIndexIsShowingOn(final Component component)
	{
		final GraphicsDevice graphicsDevice = getGraphicsDeviceIsShowingOn(component);
		final GraphicsDevice[] graphicsDevices = getAvailableScreens();
		for (int i = 0; i < graphicsDevices.length; i++)
		{
			if (graphicsDevices[i].equals(graphicsDevice))
			{
				return i;
			}
		}
		return 0;
	}
1072524
public int getPixelSize(Component component) {
        if (unit == PIXEL) {
            return intValue();
        } else if (unit == POINT) {
            return Sizes.pointAsPixel(intValue(), component);
        } else if (unit == INCH) {
            return Sizes.inchAsPixel(value, component);
        } else if (unit == MILLIMETER) {
            return Sizes.millimeterAsPixel(value, component);
        } else if (unit == CENTIMETER) {
            return Sizes.centimeterAsPixel(value, component);
        } else if (unit == DIALOG_UNITS_X) {
            return Sizes.dialogUnitXAsPixel(intValue(), component);
        } else if (unit == DIALOG_UNITS_Y) {
            return Sizes.dialogUnitYAsPixel(intValue(), component);
        } else {
            throw new IllegalStateException("Invalid unit " + unit);
        }
    }
597541
protected static BufferedImage loadImage (File file, boolean useFastIO)
        throws IOException
    {
        if (file == null) {
            return null;
        } else if (useFastIO) {
            return FastImageIO.read(file);
        }
        return ImageIO.read(file);
    }
75438
public BufferedImage createImage (int width, int height, int trans)
    {
        // DEBUG: override transparency for the moment on all images
        trans = Transparency.TRANSLUCENT;
        if (_gc != null) {
            return _gc.createCompatibleImage(width, height, trans);
        } else {
            // if we're running in headless mode, do everything in 24-bit
            return new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
        }
    }
41196
public BufferedImage getBufferedImage(int width, int height, int type) {
        int wDif,
                hDif,
                fWidth = 0,
                fHeight = 0;

        double imgWidth,
                imgHeight;

        double factor;
        imgWidth = image.getWidth();
        imgHeight = image.getHeight();


        switch (type) {
            case PROPORTIONAL:
                wDif = (int) imgWidth - width;
                hDif = (int) imgHeight - height;
                if (wDif > hDif) {
                    factor = width / imgWidth;
                } else {
                    factor = height / imgHeight;
                }
                fWidth = (int) Math.floor(imgWidth * factor);
                fHeight = (int) Math.floor(imgHeight * factor);
                break;
        }
        return getBufferedImage(fWidth, fHeight);
    }
710883
public static BufferedImage convertImageToARGB( Image image ) {
		if ( image instanceof BufferedImage && ((BufferedImage)image).getType() == BufferedImage.TYPE_INT_ARGB )
			return (BufferedImage)image;
		BufferedImage p = new BufferedImage( image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB);
		Graphics2D g = p.createGraphics();
		g.drawImage( image, 0, 0, null );
		g.dispose();
		return p;
	}
759092
public static BufferedImage cloneImage( BufferedImage image ) {
		BufferedImage newImage = new BufferedImage( image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB );
		Graphics2D g = newImage.createGraphics();
		g.drawRenderedImage( image, null );
		g.dispose();
		return newImage;
	}
962560
@Override
	public synchronized ByteBuffer getImageBytes() {
		final BufferedImage bi = getImage();
		if (bi == null) {
			return null;
		}
		return ByteBuffer.wrap(ImageUtils.imageToBytes(bi));
	}
1346537
public BufferedImage getBufferedImage()
    {
        if (image == null || abort)
            return null;
        
        // no container that would repaint -- wait for the complete image
        if (container == null)
            waitForLoad();
        
        BufferedImage img = new BufferedImage(getIntrinsicWidth(), getIntrinsicHeight(), BufferedImage.TYPE_INT_ARGB);
        Graphics2D g = img.createGraphics();
        g.drawImage(image, null, null);
        g.dispose();

        return img;
    }