当前位置:首页 » 编程语言 » java图片透明

java图片透明

发布时间: 2022-12-18 04:12:35

java 图片背景怎样设置成透明

这个应该是用PS修改图片吧,和程序没有关系吧。

PS:图片没有圆形的,都会有一个背景在里边的。

Ⅱ JAVA 怎么样判断图片是不是透明的呢,我的图片是从一整张图片上用getsubimage截图下来的。

首先将图片弄成BufferedImage对象
然后可以用getRGB方法弄到图片上的点的颜色值

然后就可以判断它的alpha通道是否等于0,等于就是透明的
(image.getRGB(i,j)>>24)==0

Ⅲ java完全透明是多少

完全透明是0,完全不透明是255;参考下面我写的静态java图片透明度处理方法吧
/**
* 设置图片透明度(异常则返回源图片)
* @param img 源图片
* @param alf 透明度(范围0-1)
* @return
*/
public static Image alphaImage(Image img, double alf) {
if (img == null) {
return img;
}
alf = alf < 0 ? 0 : alf > 1 ? 1 : alf;

try{
int imgW = img.getWidth(null);
int imgH = img.getHeight(null);

BufferedImage bi = new BufferedImage(imgW, imgH, 3);
bi.getGraphics().drawImage(img, 0, 0, null);

int tmp = (int)(alf * 255.0);
for(int i = 0; i < imgW; i++){
for(int j = 0; j < imgH; j++) {
int rgb = bi.getRGB(i, j);
Color c = new Color(rgb);
Color cc = new Color(c.getRed(), c.getGreen(), c.getBlue(), tmp);
bi.setRGB(i, j, cc.getRGB());
}
}
return bi;
}catch(Exception e){
return img;
}
}

Ⅳ java将一张png图片中的黑色改为透明

1.用 BufferedImage img = new BufferedImage(w,h,BufferedImage.TYPE_INT_ARGB)创建内存图;
2.读入png图片;
3.把所有黑色点的(r,g,b,a)中的a赋值为0。

Ⅳ java 图片如何让白色变透明

代码:

packagecom.picture;

importjava.awt.Graphics2D;
importjava.awt.image.BufferedImage;
importjava.io.File;
importjava.io.IOException;
importjava.util.regex.Pattern;

importjavax.imageio.ImageIO;
importjavax.swing.ImageIcon;
importjavax.swing.JOptionPane;

publicclassPicture{

publicstaticvoidconvert(Stringpath){
//TODOAuto-generatedconstructorstub
try{
BufferedImageimage=ImageIO.read(newFile(path));
ImageIconimageIcon=newImageIcon(image);
BufferedImagebufferedImage=newBufferedImage(
imageIcon.getIconWidth(),imageIcon.getIconHeight(),
BufferedImage.TYPE_4BYTE_ABGR);
Graphics2Dg2D=(Graphics2D)bufferedImage.getGraphics();
g2D.drawImage(imageIcon.getImage(),0,0,
imageIcon.getImageObserver());
intalpha=0;
for(intj1=bufferedImage.getMinY();j1<bufferedImage
.getHeight();j1++){
for(intj2=bufferedImage.getMinX();j2<bufferedImage
.getWidth();j2++){
intrgb=bufferedImage.getRGB(j2,j1);
if(colorInRange(rgb))
alpha=0;
else
alpha=255;
rgb=(alpha<<24)|(rgb&0x00ffffff);
bufferedImage.setRGB(j2,j1,rgb);
}
}
g2D.drawImage(bufferedImage,0,0,imageIcon.getImageObserver());
//生成图片为PNG
StringoutFile=path.substring(0,path.lastIndexOf("."));
ImageIO.write(bufferedImage,"png",newFile(outFile+".png"));
}catch(IOExceptione){
//TODOAuto-generatedcatchblock
e.printStackTrace();
}
}

(intcolor){
intred=(color&0xff0000)>>16;
intgreen=(color&0x00ff00)>>8;
intblue=(color&0x0000ff);
if(red>=color_range&&green>=color_range&&blue>=color_range)
returntrue;
returnfalse;
}

publicstaticintcolor_range=210;
publicstaticPatternpattern=Pattern.compile("[0-9]*");

publicstaticbooleanisNo(Stringstr){
returnpattern.matcher(str).matches();
}

/**
*@paramargs
*/
publicstaticvoidmain(String[]args){
//TODOAuto-generatedmethodstub
Stringpath=JOptionPane.showInputDialog(null,"请输入图片目录");
if(path==null||!newFile(path).isDirectory()){
JOptionPane.showMessageDialog(null,"输入目录有误!");
return;
}
Stringcolor=JOptionPane.showInputDialog(null,"请输入色差范围0~255(建议10~50)");
if(isNo(color)){
color_range=255-Integer.parseInt(color);
Filefile=newFile(path);
String[]files=file.list();
for(inti=0;i<files.length;i++){
Stringext=files[i].substring(files[i].lastIndexOf(".")+1);
if(ext.equals("jpg")){
convert(path+"//"+files[i]);
}
}
JOptionPane.showMessageDialog(null,"转换完成!");
}else{
JOptionPane.showMessageDialog(null,"输入的数字有误!");
}
}

}

Ⅵ java中怎么设背景图片透明

java不能设背景图片透明,除非连窗体一起透明了。
背景图片透明了,还要背景图片干啥?
还是说背景图片周围有一些不想要的颜色?
这个只能处理图片,把需要的颜色留下,不需要的颜色删除就行了。

Ⅶ java 怎么判断png图片是否是有透明度的

Java没法判断透明度,只能判断是否是png图片。

Ⅷ Java中设置背景图片透明的是哪个方法

要在JFrame上添加背景图片,常见做法是加在layeredPane上面,并将contentPane设置成透明的即可。
// 将图片添加到layeredPane
ImageIcon img = new ImageIcon("steve.jpg");
JLabel imgLabel = new JLabel(img);
frame.getLayeredPane().add(imgLabel, new Integer(Integer.MIN_VALUE));
imgLabel.setBounds(0,0,img.getIconWidth(), img.getIconHeight());
// 将contentPane设置成透明的

热点内容
dirt5需要什么配置 发布:2024-05-20 06:02:58 浏览:542
怎么把电脑锁上密码 发布:2024-05-20 05:19:09 浏览:985
安卓为什么连上wifi后没有网络 发布:2024-05-20 05:17:50 浏览:419
安卓usb在设置哪里 发布:2024-05-20 05:03:03 浏览:187
绥化编程 发布:2024-05-20 04:59:44 浏览:991
基本原理和从头计算法 发布:2024-05-20 04:50:32 浏览:30
配置情况指的是什么 发布:2024-05-20 04:48:14 浏览:497
那个程序用来编译源文件 发布:2024-05-20 04:46:45 浏览:551
小程序需要数据库吗 发布:2024-05-20 04:35:14 浏览:338
链接sqlserver 发布:2024-05-20 04:27:53 浏览:210