package com.epoint.wdg.test;
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class ImgTest {
public static void main(String[] args) throws IOException {
File file=new File("C://Users/wdg/Desktop/people.png");
//showParamterofImg(file);
File file2=changeImgtoGray(file);
grayPicToBW(file2);
}
public static void getRGB(File file) throws IOException{
int []rgb =new int[3];
BufferedImage img=ImageIO.read(file);
int pixel=img.getRGB(2, 3);
// 下面三行代码将一个数字转换为RGB数字
rgb[0] = (pixel & 0xff0000) >> 16;
rgb[1] = (pixel & 0xff00) >> 8;
rgb[2] = (pixel & 0xff);
System.out.println(rgb[0]+"-"+rgb[1]+"-"+rgb[2]);
}
//把图片变灰色
public static File changeImgtoGray(File file) throws IOException{
float []rgb =new float[3];
BufferedImage img=ImageIO.read(file);
//现在我需要获取到没一点的rgb
int y=img.getHeight();
int x=img.getWidth();
BufferedImage grayImage = new BufferedImage(x, y, BufferedImage.TYPE_BYTE_GRAY);
for(int i=0;i<x;i++){
for(int j=0;j<y;j++){
int pixel=img.getRGB(i, j);
// grayImage.setRGB(startX, startY, w, h, rgbArray, offset, scansize);
rgb[0] = (pixel & 0xff0000) >> 16;
rgb[1] = (pixel & 0xff00) >> 8;
rgb[2] = (pixel & 0xff);
int gray=(int) (rgb[0] * 0.3 + rgb[1] * 0.59 + rgb[2] * 0.11);
Color color=new Color(gray,gray,gray);
img.setRGB(i, j, color.getRGB());
}
}
File newFile = new File("C://Users/wdg/Desktop/"+"/method5.jpg");
ImageIO.write(img, "jpg", newFile);
// grayPicToBW(newFile);
return newFile;
}
int y=img.getHeight();
int x=img.getWidth();
for(int i=0;i<x;i++){
for(int j=0;j<y;j++){
int pixel=img.getRGB(i, j);
rgb[0] = (pixel & 0xff0000) >> 16;
rgb[1] = (pixel & 0xff00) >> 8;
rgb[2] = (pixel & 0xff);
int gray=(int) (rgb[0] * 0.3 + rgb[1] * 0.59 + rgb[2] * 0.11);
Color color=new Color(gray,gray,gray);
img.setRGB(i, j, color.getRGB());
}
}
File newFile = new File("C://Users/wdg/Desktop/"+"/method5.jpg");
ImageIO.write(img, "jpg", newFile);
int pixel=img.getRGB(i, j);
int gray=(int) (rgb[0] * 0.3 + rgb[1] * 0.59 + rgb[2] * 0.11);
lor color=new Color(gray,gray,gray); img.setRGB(i, j, color.getRGB());
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有