怎么知道自己的rgb值,在电脑上用画图软件打开想要替换的图片 用提取笔提取色号 然后点击编辑颜色就可以得到你的rgb色号


import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileDescriptor;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import javax.imageio.ImageIO;
public class ImageDemoBackGround {
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
/*
* 待处理的图片
* */
File dir = new File("C://Users//10124//Desktop//个人文件//图片");
/*
* 列出目录中的图片,得到数组
* */
File[] files = dir.listFiles();
/*
* 遍历数组
* */
for (int x = 0; x < files.length; x++) {
/*
* 定义一个数组,存放RGB值
* */
int[] rgb = new int[3];
/*
* byte转换BuffereImage
* */
BufferedImage bImage = null;
bImage = ImageIO.read(files[x]);
int width = bImage.getWidth();
int height = bImage.getHeight();
int minx = bImage.getMinTileX();
int miny = bImage.getMinTileY();
System.out.println("正在处理..." + files[x].getName());
/*
* 遍历像素点,判断是否更换颜色
* */
for (int i = minx; i < width; i++) {
for (int j = miny; j < height; j++) {
/*
* 换色
* */
int pixel = bImage.getRGB(i, j);
rgb[0] = (pixel & 0xff0000) >> 16;
rgb[1] = (pixel & 0xff00) >> 8;
rgb[2] = (pixel & 0xff);
//红--> 蓝
//此处是判断RGB 的值是否是你想要替换的值
if (rgb[0] < 150 && rgb[0] > 100
&& rgb[1] < 50
&& rgb[2] < 50 ) {
//bImage.setRGB(i, j, 0x438EDB);
//替换成 蓝色
bImage.setRGB(i, j, 0xFFB6C1);
}
}
}
System.out.println("\t处理完毕:" + files[x].getName());
System.out.println();
/*
* 输出
* */
FileOutputStream ops;
try {
ops = new FileOutputStream(new File("C://Users//10124//Desktop//个人文件//图片//" + x + ".jpg"));
ImageIO.write(bImage, "jpg", ops);
ops.flush();
ops.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
该博客介绍了一个Java程序,用于读取指定目录中的图片,提取每个像素的RGB值,并根据预设条件替换特定颜色。程序遍历图像的每一个像素点,如果RGB值满足条件(红色在100到150之间,绿色和蓝色都小于50),则将该像素替换为新的颜色。处理后的图片被保存为新的文件。这是一个关于图像处理和颜色操作的示例。
2804

被折叠的 条评论
为什么被折叠?



