图片原理与处理

1、窗体初始化方法
public void InitUI(){
			this.setTitle("图像处理");
			this.setSize(1800,1800);
			this.setVisible(true);
			this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			
			
		}
2、创建一个缓冲图片,把缓冲图片的每个像素点的颜色遍历,读取到一个二维数组
public int[][] getPixelArray(String imgPath) {
			File file=new File(imgPath);
			BufferedImage buffimg=null;
			try {
				buffimg=ImageIO.read(file);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	int w=buffimg.getWidth();
		int h=buffimg.getHeight();
		int[][] imgarr=new int[w][h];
		
		for(int i=0;i<w;i++) {
			for(int j=0;j<h;j++) {
				imgarr[i][j]=buffimg.getRGB(i, j);
			}
		}
		return imgarr;	
		}
3、重写paint方法 把二维数组的像素点画出来
public void paint(Graphics g) {
			super.paint(g);
			int[][]imgarr=getPixelArray("C:\\Users\\86158\\Desktop\\微信图片_20220120191028.jpg");
					int w=imgarr.length;
			int h=imgarr[0].length;
			
			for(int i=0;i<w;i++) {
				for(int j=0;j<h;j++) {
					
					int rgb=imgarr[i][j];
					Color color=new Color(rgb);
			g.setColor(color);
g.fillRect(i, j, 1, 1);	}
4、写出许多不同的滤镜效果
温暖
int red=color.getRed();
					int green=color.getGreen();
					int blue=color.getBlue();
				 	Color warmness=new Color(red,green,blue/3);
				g.setColor(warmness);
梦幻
	Color dreamland=new Color(red,green/3*2,blue);
				g.setColor(dreamland);
底片
Color negative=new Color(255-red,255-green,255-green);
							g.setColor(negative);
马赛克
public void paint(Graphics g) {
			super.paint(g);
			int[][]imgarr=getPixelArray("C:\\Users\\86158\\Desktop\\微信图片_20220120191028.jpg");
					int w=imgarr.length;
			int h=imgarr[0].length;
			
			for(int i=0;i<w;i+=10) {
				for(int j=0;j<h;j+=10) {
					
					int rgb=imgarr[i][j];
					Color color=new Color(rgb);
				 g.setColor(color);
	
					g.fillRect(i, j, 10, 10);	
											}}
		}
黑白
int av=(red+blue+green)/3;
				Color grey=new Color(av,av,av);
				g.setColor(grey);
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Beiwen_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值