当前位置: 首页>>代码示例>>Java>>正文


Java BufferedImage.getTransparency方法代码示例

本文整理汇总了Java中java.awt.image.BufferedImage.getTransparency方法的典型用法代码示例。如果您正苦于以下问题:Java BufferedImage.getTransparency方法的具体用法?Java BufferedImage.getTransparency怎么用?Java BufferedImage.getTransparency使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.image.BufferedImage的用法示例。


在下文中一共展示了BufferedImage.getTransparency方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getOutputFormat

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
@Override
public String getOutputFormat(String tx_name,String tx_path,String substance_fs_path) {
	tx_name=tx_name.substring(tx_name.lastIndexOf("_")+1);
	boolean has_alpha=false;
	try{
		BufferedImage bimg=ImageIO.read(new File(PathUtils.toNative(substance_fs_path+tx_path)));
		has_alpha=bimg.getTransparency()==BufferedImage.TRANSLUCENT;
	}catch(Exception e){
		LOGGER.log(Level.WARNING,"Can't read image",e);
	}
	if(has_alpha)LOGGER.log(Level.FINE,tx_name+" has alpha channel.");
	switch(tx_name){
		case "DiffuseMap":
			return has_alpha?"S3TC_DXT5":"S3TC_DXT1";
		case "SpecularMap":
			return "S3TC_DXT1";
		case "GlowMap":
			return "S3TC_DXT1";
	
		case "NormalMap":
			return "rgb8";
		case "ParallaxMap":
			return "rgb8";
	}
	return null;
}
 
开发者ID:riccardobl,项目名称:JMELink-SP,代码行数:27,代码来源:PhongSubstance.java

示例2: toCompatibleImage

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
public static BufferedImage toCompatibleImage(BufferedImage src) {
  if ((src.getColorModel().equals(compatOpaqueImage.getColorModel()) &&
       src.getTransparency() == compatOpaqueImage.getTransparency())
      ||
      (src.getColorModel().equals(compatTransImage.getColorModel()) &&
       src.getTransparency() == compatTransImage.getTransparency()))
  {
    return src;
  }

  final BufferedImage dst = createCompatibleImage(
    src.getWidth(), src.getHeight(), isTransparent(src)
  );

  final Graphics2D g = dst.createGraphics();
  g.drawImage(src, 0, 0, null);
  g.dispose();

  return dst;
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:21,代码来源:ImageUtils.java

示例3: getScaleZoom

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
/**
 * 按比例缩放
 * @param img
 * @return
 */
public static BufferedImage getScaleZoom(BufferedImage img, int targetSize) {
	int srcWidth = img.getWidth();
	int srcHeight = img.getHeight();
	int targetWidth = targetSize;
	int targetHeight = targetSize;
	if (targetSize>srcWidth || targetSize>srcHeight){
		targetWidth = srcWidth;
		targetHeight = srcHeight;
	}
	double rate1 = ((double)srcWidth)/targetWidth;
	double rate2 = ((double)srcHeight)/targetHeight;
       // 根据缩放比率大的进行缩放控制 
       double rate = rate1 > rate2 ? rate1 : rate2;
       int newWidth = (int)(((double)srcWidth)/rate);
       int newHeight = (int)(((double)srcHeight)/rate);
	int imageType = (img.getTransparency() == Transparency.OPAQUE) ? BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB;
	BufferedImage tag = new BufferedImage(newWidth, newHeight, imageType);
	//Image.SCALE_SMOOTH 的缩略算法 生成缩略图片的平滑度的优先级比速度高 生成的图片质量比较好 但速度慢
	Image scaledImage = img.getScaledInstance(newWidth, newHeight, Image.SCALE_REPLICATE);
	tag.getGraphics().drawImage(scaledImage, 0, 0, null);
	
	return tag;
}
 
开发者ID:lemon-china,项目名称:lemon-framework,代码行数:29,代码来源:ImageUtil.java

示例4: getOutputFormat

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
@Override
public String getOutputFormat(String tx_name, String tx_path, String substance_fs_path) {
	if(tx_path.isEmpty()) return tx_path;
	tx_name=tx_name.substring(tx_name.lastIndexOf("_")+1);
	boolean has_alpha=false;
	try{
		File f=new File(PathUtils.toNative(substance_fs_path+"/"+tx_path));
		System.out.println(f);
		BufferedImage bimg=ImageIO.read(f);
		has_alpha=bimg.getTransparency()==BufferedImage.TRANSLUCENT;
	}catch(Exception e){
		LOGGER.log(Level.WARNING,"Can't read image",e);
	}
	if(has_alpha) LOGGER.log(Level.FINE,tx_name+" has alpha channel.");
	switch(tx_name){
		case "BaseColorMap":
			return has_alpha?"S3TC_DXT5":"S3TC_DXT1";
		case "MetallicMap":
			return "S3TC_DXT1";
		case "RoughnessMap":
			return "S3TC_DXT1";
		case "EmissiveMap":
			return "S3TC_DXT1";
		case "NormalMap":
			return "rgb8";
		case "ParallaxMap":
			return "rgb8";
	}
	return null;
}
 
开发者ID:riccardobl,项目名称:JMELink-SP,代码行数:31,代码来源:PBRSubstance.java

示例5: cloneImageRegion

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
public static BufferedImage cloneImageRegion(BufferedImage srcImg, int x, int y, int width, int height) {
    int imgType = (srcImg.getTransparency() == Transparency.OPAQUE)
            ? BufferedImage.TYPE_INT_RGB
            : BufferedImage.TYPE_INT_ARGB;
    BufferedImage newImage = new BufferedImage(width, height, imgType);
    Graphics2D g2 = newImage.createGraphics();
    g2.drawImage(srcImg.getSubimage(x, y, width, height), 0, 0, null);
    g2.dispose();

    return newImage;
}
 
开发者ID:mcdcorp,项目名称:opentest,代码行数:12,代码来源:ImageUtil.java

示例6: getScaleCutscale

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
/**
 * 按比例裁剪
 * @param img
 * @param targetWidth
 * @param targetHeight
 * @return
 */
public static BufferedImage getScaleCutscale(BufferedImage img, int targetWidth, int targetHeight) {
	int srcWidth = img.getWidth();
	int srcHeight = img.getHeight();
	//当超过图片最大宽高时候等比缩小所需要的图片规格
	while(targetWidth>srcWidth || targetHeight>srcHeight){
		double rt = (targetWidth>srcWidth)? ((double)targetWidth)/(srcWidth): ((double)targetHeight)/(srcHeight);
		targetWidth = (int)(((double)targetWidth)/rt);
		targetHeight = (int)(((double)targetHeight)/rt);
	}

	double rate1 = ((double)srcWidth)/(targetWidth);
	double rate2 = ((double)srcHeight)/(targetHeight);
       // 根据缩放比率大的进行缩放控制 
       double rate = rate1 < rate2 ? rate1 : rate2; 
       int newWidth = (int)(((double)srcWidth)/rate);
       int newHeight = (int)(((double)srcHeight)/rate);

       int x1 = newWidth/2 - targetWidth/2;
       int x2 = newWidth/2 + targetWidth/2;
       int y1 = newHeight/2 - targetHeight/2;
       int y2 = newHeight/2 + targetHeight/2;
	int imageType = (img.getTransparency() == Transparency.OPAQUE) ? BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB;
	BufferedImage tag = new BufferedImage(targetWidth, targetHeight, imageType);
    Image scaledImage = img.getScaledInstance(newWidth, newHeight, Image.SCALE_REPLICATE);
	tag.getGraphics().drawImage(scaledImage, 0, 0, targetWidth, targetHeight, x1, y1, x2, y2, null);
	
	return tag;
}
 
开发者ID:lemon-china,项目名称:lemon-framework,代码行数:36,代码来源:ImageUtil.java

示例7: isTransparent

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
public static boolean isTransparent(BufferedImage img) {
  return img.getTransparency() != BufferedImage.OPAQUE;
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:4,代码来源:ImageUtils.java

示例8: zoom

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
/**
 * 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
  );
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:69,代码来源:GeneralFilter.java

示例9: copyToOptimalImage

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
/**
    * Used to copy a {@link BufferedImage} from a non-optimal type into a new
    * {@link BufferedImage} instance of an optimal type (RGB or ARGB). If
    * <code>src</code> is already of an optimal type, then it is returned
    * unmodified.
    * <p/>
    * This method is meant to be used by any calling code (imgscalr's or
    * otherwise) to convert any inbound image from a poorly supported image
    * type into the 2 most well-supported image types in Java2D (
    * {@link BufferedImage#TYPE_INT_RGB} or {@link BufferedImage#TYPE_INT_ARGB}
    * ) in order to ensure all subsequent graphics operations are performed as
    * efficiently and correctly as possible.
    * <p/>
    * When using Java2D to work with image types that are not well supported,
    * the results can be anything from exceptions bubbling up from the depths
    * of Java2D to images being completely corrupted and just returned as solid
    * black.
    * 
    * @param src
    *            The image to copy (if necessary) into an optimally typed
    *            {@link BufferedImage}.
    * 
    * @return a representation of the <code>src</code> image in an optimally
    *         typed {@link BufferedImage}, otherwise <code>src</code> if it was
    *         already of an optimal type.
    * 
    * @throws IllegalArgumentException
    *             if <code>src</code> is <code>null</code>.
    */
   protected static BufferedImage copyToOptimalImage(BufferedImage src) throws IllegalArgumentException {
if (src == null)
    throw new IllegalArgumentException("src cannot be null");

// Calculate the type depending on the presence of alpha.
int type = (src.getTransparency() == Transparency.OPAQUE ? BufferedImage.TYPE_INT_RGB
	: BufferedImage.TYPE_INT_ARGB);
BufferedImage result = new BufferedImage(src.getWidth(), src.getHeight(), type);

// Render the src image into our new optimal source.
Graphics g = result.getGraphics();
g.drawImage(src, 0, 0, null);
g.dispose();

return result;
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:46,代码来源:Scalr.java

示例10: copyToOptimalImage

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
/**
 * Used to copy a {@link BufferedImage} from a non-optimal type into a new
 * {@link BufferedImage} instance of an optimal type (RGB or ARGB). If
 * <code>src</code> is already of an optimal type, then it is returned
 * unmodified.
 * <p/>
 * This method is meant to be used by any calling code (imgscalr's or
 * otherwise) to convert any inbound image from a poorly supported image
 * type into the 2 most well-supported image types in Java2D (
 * {@link BufferedImage#TYPE_INT_RGB} or {@link BufferedImage#TYPE_INT_ARGB}
 * ) in order to ensure all subsequent graphics operations are performed as
 * efficiently and correctly as possible.
 * <p/>
 * When using Java2D to work with image types that are not well supported,
 * the results can be anything from exceptions bubbling up from the depths
 * of Java2D to images being completely corrupted and just returned as solid
 * black.
 * 
 * @param src
 *            The image to copy (if necessary) into an optimally typed
 *            {@link BufferedImage}.
 * 
 * @return a representation of the <code>src</code> image in an optimally
 *         typed {@link BufferedImage}, otherwise <code>src</code> if it was
 *         already of an optimal type.
 * 
 * @throws IllegalArgumentException
 *             if <code>src</code> is <code>null</code>.
 */
protected static BufferedImage copyToOptimalImage(BufferedImage src)
		throws IllegalArgumentException {
	if (src == null)
		throw new IllegalArgumentException("src cannot be null");

	// Calculate the type depending on the presence of alpha.
	int type = (src.getTransparency() == Transparency.OPAQUE ? BufferedImage.TYPE_INT_RGB
			: BufferedImage.TYPE_INT_ARGB);
	BufferedImage result = new BufferedImage(src.getWidth(),
			src.getHeight(), type);

	// Render the src image into our new optimal source.
	Graphics g = result.getGraphics();
	g.drawImage(src, 0, 0, null);
	g.dispose();

	return result;
}
 
开发者ID:bloc97,项目名称:ConvNetCL4J,代码行数:48,代码来源:Scalr.java

示例11: getScaledInstance

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
/**
 * Gets the scaledInstance attribute of the YassUtils object
 *
 * @param img          Description of the Parameter
 * @param targetWidth  Description of the Parameter
 * @param targetHeight Description of the Parameter
 * @return The scaledInstance value
 */
public static BufferedImage getScaledInstance(BufferedImage img, int targetWidth, int targetHeight) {
    boolean higherQuality = true;
    Object hint = RenderingHints.VALUE_INTERPOLATION_BICUBIC;

    int type = (img.getTransparency() == Transparency.OPAQUE) ? BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB;
    BufferedImage ret = img;
    int w;
    int h;
    if (higherQuality) {
        // Use multi-step technique: start with original size, then
        // scale down in multiple passes with drawImage()
        // until the target size is reached
        w = img.getWidth();
        h = img.getHeight();
    } else {
        // Use one-step technique: scale directly from original
        // size to target size with a single drawImage() call
        w = targetWidth;
        h = targetHeight;
    }

    do {
        if (higherQuality && w > targetWidth) {
            w /= 2;
            if (w < targetWidth) {
                w = targetWidth;
            }
        }

        if (higherQuality && h > targetHeight) {
            h /= 2;
            if (h < targetHeight) {
                h = targetHeight;
            }
        }

        BufferedImage tmp = new BufferedImage(w, h, type);
        Graphics2D g2 = tmp.createGraphics();
        g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, hint);
        g2.drawImage(ret, 0, 0, w, h, null);
        g2.dispose();

        ret = tmp;
    } while (w != targetWidth || h != targetHeight);

    return ret;
}
 
开发者ID:SarutaSan72,项目名称:Yass,代码行数:56,代码来源:YassUtils.java

示例12: createOptimalImage

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
/**
    * Used to create a {@link BufferedImage} with the given dimensions and the
    * most optimal RGB TYPE ( {@link BufferedImage#TYPE_INT_RGB} or
    * {@link BufferedImage#TYPE_INT_ARGB} ) capable of being rendered into from
    * the given <code>src</code>.
    * <p/>
    * This does not perform a copy of the image data from <code>src</code> into
    * the result image; see {@link #copyToOptimalImage(BufferedImage)} for
    * that.
    * <p/>
    * We force all rendering results into one of these two types, avoiding the
    * case where a source image is of an unsupported (or poorly supported)
    * format by Java2D causing the rendering result to end up looking terrible
    * (common with GIFs) or be totally corrupt (e.g. solid black image).
    * <p/>
    * Originally reported by Magnus Kvalheim from Movellas when scaling certain
    * GIF and PNG images.
    * 
    * @param src
    *            The source image that will be analyzed to determine the most
    *            optimal image type it can be rendered into.
    * @param width
    *            The width of the newly created resulting image.
    * @param height
    *            The height of the newly created resulting image.
    * 
    * @return a new {@link BufferedImage} representing the most optimal target
    *         image type that <code>src</code> can be rendered into.
    * 
    * @throws IllegalArgumentException
    *             if <code>width</code> or <code>height</code> are &lt; 0.
    * 
    * @see <a
    *      href="http://www.mail-archive.com/[email protected]/msg05621.html">How
    *      Java2D handles poorly supported image types</a>
    * @see <a
    *      href=
    *      "http://code.google.com/p/java-image-scaling/source/browse/trunk/src/main/java/com/mortennobel/imagescaling/MultiStepRescaleOp.java">Thanks
    *      to Morten Nobel for implementation hint</a>
    */
   protected static BufferedImage createOptimalImage(BufferedImage src, int width, int height)
    throws IllegalArgumentException {
if (width <= 0 || height <= 0)
    throw new IllegalArgumentException("width [" + width + "] and height [" + height + "] must be > 0");

return new BufferedImage(width, height, (src.getTransparency() == Transparency.OPAQUE
	? BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB));
   }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:49,代码来源:Scalr.java

示例13: createOptimalImage

import java.awt.image.BufferedImage; //导入方法依赖的package包/类
/**
 * Used to create a {@link BufferedImage} with the given dimensions and the
 * most optimal RGB TYPE ( {@link BufferedImage#TYPE_INT_RGB} or
 * {@link BufferedImage#TYPE_INT_ARGB} ) capable of being rendered into from
 * the given <code>src</code>.
 * <p/>
 * This does not perform a copy of the image data from <code>src</code> into
 * the result image; see {@link #copyToOptimalImage(BufferedImage)} for
 * that.
 * <p/>
 * We force all rendering results into one of these two types, avoiding the
 * case where a source image is of an unsupported (or poorly supported)
 * format by Java2D causing the rendering result to end up looking terrible
 * (common with GIFs) or be totally corrupt (e.g. solid black image).
 * <p/>
 * Originally reported by Magnus Kvalheim from Movellas when scaling certain
 * GIF and PNG images.
 * 
 * @param src
 *            The source image that will be analyzed to determine the most
 *            optimal image type it can be rendered into.
 * @param width
 *            The width of the newly created resulting image.
 * @param height
 *            The height of the newly created resulting image.
 * 
 * @return a new {@link BufferedImage} representing the most optimal target
 *         image type that <code>src</code> can be rendered into.
 * 
 * @throws IllegalArgumentException
 *             if <code>width</code> or <code>height</code> are &lt; 0.
 * 
 * @see <a
 *      href="http://www.mail-archive.com/[email protected]/msg05621.html">How
 *      Java2D handles poorly supported image types</a>
 * @see <a
 *      href="http://code.google.com/p/java-image-scaling/source/browse/trunk/src/main/java/com/mortennobel/imagescaling/MultiStepRescaleOp.java">Thanks
 *      to Morten Nobel for implementation hint</a>
 */
protected static BufferedImage createOptimalImage(BufferedImage src,
		int width, int height) throws IllegalArgumentException {
	if (width <= 0 || height <= 0)
		throw new IllegalArgumentException("width [" + width
				+ "] and height [" + height + "] must be > 0");

	return new BufferedImage(
			width,
			height,
			(src.getTransparency() == Transparency.OPAQUE ? BufferedImage.TYPE_INT_RGB
					: BufferedImage.TYPE_INT_ARGB));
}
 
开发者ID:bloc97,项目名称:ConvNetCL4J,代码行数:52,代码来源:Scalr.java


注:本文中的java.awt.image.BufferedImage.getTransparency方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。