Java Code Examples for java.awt.image.BufferedImage#OPAQUE

The following examples show how to use java.awt.image.BufferedImage#OPAQUE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GraphicUtils.java    From xyTalk-pc with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
    * Converts a File holding an Image into a Buffered Image
    * 
    * @param file
    *            {@link File}
    * @return {@link BufferedImage}
    */
   public static BufferedImage getBufferedImage(File file) {
// Why wasn't this using it's code that pulled from the file? Hrm.
   //Icon icon = SparkRes.getImageIcon(SparkRes.DOCUMENT_INFO_32x32);
   Icon icon = null;

BufferedImage bi = new BufferedImage(icon.getIconWidth(),
	icon.getIconHeight(), BufferedImage.OPAQUE);
Graphics bg = bi.getGraphics();

ImageIcon i = (ImageIcon) icon;

bg.drawImage(i.getImage(), 0, 0, null);
bg.dispose();

return bi;
   }
 
Example 2
Source File: GraphicUtils.java    From Spark with Apache License 2.0 6 votes vote down vote up
/**
    * Converts a File holding an Image into a Buffered Image
    * 
    * @param file
    *            {@link File}
    * @return {@link BufferedImage}
    */
   public static BufferedImage getBufferedImage(File file) {
// Why wasn't this using it's code that pulled from the file? Hrm.
Icon icon = SparkRes.getImageIcon(SparkRes.DOCUMENT_INFO_32x32);

BufferedImage bi = new BufferedImage(icon.getIconWidth(),
	icon.getIconHeight(), BufferedImage.OPAQUE);
Graphics bg = bi.getGraphics();

ImageIcon i = (ImageIcon) icon;

bg.drawImage(i.getImage(), 0, 0, null);
bg.dispose();

return bi;
   }
 
Example 3
Source File: ImageCreator.java    From TeaStore with Apache License 2.0 5 votes vote down vote up
/**
 * Create an image with the given number of shapes, with the given size. The shapes will be added to the supplied 
 * buffered image using the given random number generator.
 * @param shapesPerImage Number of shapes added to the buffered image.
 * @param categoryImg Image added at the end representing the product category.
 * @param size Size of the image in pixel.
 * @param rand Random number generator.
 * @return Returns the given buffered image with the added shapes and category image.
 */
public static BufferedImage createImage(int shapesPerImage, BufferedImage categoryImg,
    ImageSize size, Random rand) {
  BufferedImage img = new BufferedImage(size.getWidth(), size.getHeight(), BufferedImage.OPAQUE);
  Graphics2D graphics = img.createGraphics();
  graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
      RenderingHints.VALUE_INTERPOLATION_BICUBIC);

  switchColor(graphics, rand);
  graphics.fillRect(0, 0, size.getWidth(), size.getHeight());

  for (int i = 0; i < shapesPerImage; i++) {
    switch (rand.nextInt(4)) {
    case 0:
      makeRectangle(graphics, size, rand);
      break;
    case 1:
      makeLine(graphics, size, rand);
      break;
    case 2:
      makeOval(graphics, size, rand);
      break;
    case 3:
      makeText(graphics, size, rand);
      break;
    default:
      makeRectangle(graphics, size, rand);
      break;
    }
  }

  if (categoryImg != null) {
    drawCategoryImage(graphics, size, categoryImg, rand);
  }

  graphics.dispose();
  return img;
}