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

The following are Jave code examples for showing how to use TRANSLUCENT 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: JMELink-SP   File: PhongSubstance.java   View Source Code Vote up 7 votes
@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;
}
 
Example 2
Project: MTG-Card-Recognizer   File: ImageUtil.java   View Source Code Vote up 7 votes
public static BufferedImage getScaledImage(BufferedImage src, double fraction){
	int finalw = (int)(src.getWidth()*fraction);
	int finalh = (int)(src.getHeight()*fraction);
	double factor = 1.0d;
	if(src.getWidth() > src.getHeight()){
		factor = ((double)src.getHeight()/(double)src.getWidth());
		finalh = (int)(finalw * factor);                
	}else{
		factor = ((double)src.getWidth()/(double)src.getHeight());
		finalw = (int)(finalh * factor);
	}   

	BufferedImage resizedImg = new BufferedImage(finalw, finalh, BufferedImage.TRANSLUCENT);
	Graphics2D g2 = resizedImg.createGraphics();
	g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
	g2.drawImage(src, 0, 0, finalw, finalh, null);
	g2.dispose();
	return resizedImg;
}
 
Example 3
Project: Pet-Supply-Store   File: ImageScaler.java   View Source Code Vote up 6 votes
/**
 * Scales a given image by rendering the supplied image with the given width and height into a new image and 
 * returning the new image. The method will throw an  {@link java.lang.IllegalArgumentException} if either of the 
 * two image sizes is 0 or below. A {@link java.lang.NullPointerException} will be thrown if the supplied image 
 * is null.
 * @param image Image to scale to the given width and height
 * @param width Width to scale image to
 * @param height Height to scale image to
 * @return New image scaled to the given width and height
 */
public static BufferedImage scale(BufferedImage image, int width, int height) {
	if (image == null) {
		log.error("The supplied image is null.");
		throw new NullPointerException("The supplied image is null.");
	}
	if (width <= 0) {
		log.error("The supplied pixel width is below 1.");
		throw new IllegalArgumentException("The supplied pixel width is below 1.");
	}
	if (height <= 0) {
		log.error("The supplied pixel height is below 1.");
		throw new IllegalArgumentException("The supplied pixel height is below 1.");
	}
	
	BufferedImage scaledImg = new BufferedImage(width, height, BufferedImage.TRANSLUCENT);
	Graphics2D graphics = scaledImg.createGraphics();
	graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
	graphics.drawImage(image, 0, 0, width, height, null);
	graphics.dispose();
	return scaledImg;
}
 
Example 4
Project: MTG-Card-Recognizer   File: ImageUtil.java   View Source Code Vote up 6 votes
public static BufferedImage getScaledImage(BufferedImage src){
	int finalw = SQUARE_SIZE;
	int finalh = SQUARE_SIZE;
	double factor = 1.0d;
	if(src.getWidth() > src.getHeight()){
		factor = ((double)src.getHeight()/(double)src.getWidth());
		finalh = (int)(finalw * factor);                
	}else{
		factor = ((double)src.getWidth()/(double)src.getHeight());
		finalw = (int)(finalh * factor);
	}   

	BufferedImage resizedImg = new BufferedImage(finalw, finalh, BufferedImage.TRANSLUCENT);
	Graphics2D g2 = resizedImg.createGraphics();
	g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
	g2.drawImage(src, 0, 0, finalw, finalh, null);
	g2.dispose();
	return resizedImg;
}
 
Example 5
Project: Quavo   File: ImageUtils.java   View Source Code Vote up 6 votes
public static BufferedImage getScaledImage(BufferedImage src, double factor) {
	int finalw = src.getWidth();
	int finalh = src.getHeight();
	if (src.getWidth() > src.getHeight()) {
		factor = ((double) src.getHeight() / (double) src.getWidth());
		finalh = (int) (finalw * factor);
	}

	else {
		factor = ((double) src.getWidth() / (double) src.getHeight());
		finalw = (int) (finalh * factor);
	}

	BufferedImage resizedImg = new BufferedImage(finalw, finalh, BufferedImage.TRANSLUCENT);
	Graphics2D g2 = resizedImg.createGraphics();
	g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
	g2.drawImage(src, 0, 0, finalw, finalh, null);
	g2.dispose();
	return resizedImg;
}
 
Example 6
Project: JMELink-SP   File: PBRSubstance.java   View Source Code Vote up 5 votes
@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;
}
 
Example 7
Project: Caritemere   File: GuiUtil.java   View Source Code Vote up 5 votes
public BufferedImage tint(BufferedImage src, Color col) {
	BufferedImage img = new BufferedImage(src.getWidth(), src.getHeight(), BufferedImage.TRANSLUCENT);
	Graphics2D graphics = img.createGraphics();
	graphics.setXORMode(new Color(col.getRed(), col.getGreen(), col.getBlue(), 0));
	graphics.drawImage(src, null, 0, 0);
	graphics.dispose();
	return img;
}