java图片对比度调整示例代码
前言
本文主要给大家介绍了关于java图片对比度调整的方法,分享出来供大家参考学习,下面话不多说了,来一起看看详细的介绍吧
方法如下
测试代码
publicstaticvoidmain(String[]args){
//文件与BufferedImage间的转换
BufferedImagebi=file2img("test.jpg");//读取图片
BufferedImagebii=img_color_contrast(bi,100);
img2file(bii,"jpg","test1.jpg");//生成图片
}
图片对比度调整代码
//图片对比度调整
publicstaticBufferedImageimg_color_contrast(BufferedImageimgsrc,intcontrast){
try{
intcontrast_average=128;
//创建一个不带透明度的图片
BufferedImageback=newBufferedImage(imgsrc.getWidth(),imgsrc.getHeight(),BufferedImage.TYPE_INT_RGB);
intwidth=imgsrc.getWidth();
intheight=imgsrc.getHeight();
intpix;
for(inti=0;i255)pix=255;
}
intred=pix;
if(color.getGreen()255)pix=255;
}
intgreen=pix;
if(color.getBlue()255)pix=255;
}
intblue=pix;
color=newColor(red,green,blue);
intx=color.getRGB();
back.setRGB(j,i,x);
}
}
returnback;
}catch(Exceptione){
e.printStackTrace();
returnnull;
}
}
图片读取,和存储函数
//读取图片
publicstaticBufferedImagefile2img(Stringimgpath){
try{
BufferedImagebufferedImage=ImageIO.read(newFile(imgpath));
returnbufferedImage;
}catch(Exceptione){
e.printStackTrace();
returnnull;
}
}
//保存图片,extent为格式,"jpg"、"png"等
publicstaticvoidimg2file(BufferedImageimg,Stringextent,Stringnewfile){
try{
ImageIO.write(img,extent,newFile(newfile));
}catch(Exceptione){
e.printStackTrace();
}
}
热门推荐
1 训练狗狗搜寻
2 如何训练狗狗装死
3 狗狗训练书
6 怎么训练狗狗拜年
8 狗狗训练游戏
10 狗狗嗅觉训练
11 怎么训练狗狗在笼子里不叫
12 怎么训练狗狗站立走路
13 怎么训练狗狗在马桶上
14 狗狗尿尿怎么训练
15 训练狗狗用品
16 泰迪狗狗的训练方法大小便
17 训练狗狗可以打吗
18 王曼丽的狗狗训练