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

The following are Jave code examples for showing how to use OPAQUE of the java.awt.image.BufferedImage class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Pet-Supply-Store   File: ImageCreator.java   View Source Code Vote up 6 votes
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;
		}
	}
	
	if (categoryImg != null) {
		drawCategoryImage(graphics, size, categoryImg, rand);
	}
	
	graphics.dispose();
	return img;
}
 
Example 2
Project: VASSAL-src   File: ImageUtils.java   View Source Code Vote up 4 votes
public static boolean isTransparent(BufferedImage img) {
  return img.getTransparency() != BufferedImage.OPAQUE;
}
 
Example 3
Project: VASSAL-src   File: GeneralFilter.java   View Source Code Vote up 4 votes
/**
 * Filters a portion of the source image.
 *
 * @param dstR the destination tile to calculate
 * @param dst_fr the bounds of the whole destination image
 * @param srcI the source image
 * @param filter the filter to apply
 * @throws ClassCastException if <code>srcI</code> does not store its data
 * in a {@link DataBufferInt}
 */
public static void zoom(
  WritableRaster dstR,
  Rectangle dst_fr,
  BufferedImage srcI,
  final Filter filter)
{
  final int dst_data[] = ((DataBufferInt) dstR.getDataBuffer()).getData();

  final int src_type;
  if (srcI.getTransparency() == BufferedImage.OPAQUE) {
    src_type = OPAQUE;
  }
  else if (srcI.isAlphaPremultiplied()) {
    src_type = TRANS_PREMULT;
  }
  else {
    src_type = TRANS_UNPREMULT;
  }

  final int dx0 = dstR.getMinX();
  final int dy0 = dstR.getMinY();
  final int dx1 = dx0 + dstR.getWidth() - 1;
  final int dy1 = dy0 + dstR.getHeight() - 1;
  final int dw = dstR.getWidth();
  final int dh = dstR.getHeight();

  final int dstWidth = dst_fr.width;
  final int dstHeight = dst_fr.height;

  final int srcWidth = srcI.getWidth();
  final int srcHeight = srcI.getHeight();

  // We want dstX0 * xscale = srcX0, except when that would make
  // xscale = 0; similarly for yscale.
  final float xscale =
    srcWidth == 1 ? dstWidth : (float)(dstWidth-1) / (srcWidth-1);
  final float yscale =
    srcHeight == 1 ? dstHeight : (float)(dstHeight-1) / (srcHeight-1);

  final float fwidth = filter.getSamplingRadius();

  final int sx0 = Math.max(0, (int) Math.floor((dx0-fwidth)/xscale));
  final int sy0 = Math.max(0, (int) Math.floor((dy0-fwidth)/yscale));
  final int sx1 = Math.min(srcWidth-1, (int) Math.ceil((dx1+fwidth)/xscale));
  final int sy1 = Math.min(srcHeight-1, (int) Math.ceil((dy1+fwidth)/yscale));
  final int sw = sx1 - sx0 + 1;
  final int sh = sy1 - sy0 + 1;

  final int src_data[] =
    ((DataBufferInt) srcI.getRaster().getDataBuffer()).getData();

  resample(
    src_data, false,
    sx0, sy0, sx1, sy1, sw, sh, src_type, srcWidth, srcHeight,
    dst_data, dx0, dy0, dx1, dy1, dw, dh, dstWidth, dstHeight,
    xscale, yscale, filter
  );
}