zoukankan      html  css  js  c++  java
  • 图片旋转翻转

    	/**
    	 * 水平翻转图像
    	 * @param img
    	 * @return
    	 */
    	public Image flipImage_H(Image img)
    	{
    		int width = img.getWidth(null);
    		int height = img.getHeight(null);
    		BufferedImage newImg = new BufferedImage(width, height, 1);
    		Graphics g = newImg.getGraphics();
    		g.drawImage(img, 0, 0, width, height, width, 0, 0, height, null);
    		g.dispose();
    		return newImg;
    	}
    	
    	/**
    	 * 竖直翻转图像
    	 * @param img
    	 * @return
    	 */
    	public Image flipImage_V(Image img)
    	{
    		int width = img.getWidth(null);
    		int height = img.getHeight(null);
    		BufferedImage newImg = new BufferedImage(width, height, 1);
    		Graphics g = newImg.getGraphics();
    		Graphics2D g2d = (Graphics2D) g;
    //		g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.DST_IN, 0.1f));
    		g2d.drawImage(img, 0, 0, width, height, 0, height, width, 0, null);
    		g2d.dispose();
    		return newImg;
    	}
    	
    	
    	/**
    	 * 顺时针转90度
    	 * @param img
    	 * @return
    	 */
    	public Image getImage_rote90(Image img)
    	{
    		int width = img.getWidth(null);
    		int height = img.getHeight(null);
    		BufferedImage newImg = new BufferedImage(height, width, 1);
    		Graphics g = newImg.getGraphics();
    		Graphics2D g2d = (Graphics2D) g;
    		g2d.rotate(Math.toRadians(90), height, 0);
    		g2d.drawImage(img, height, 0, width, height,  null);
    		g2d.dispose();
    		return newImg;
    	}
    	
    	
    	/**
    	 * 顺时针转180
    	 * @param img
    	 * @return
    	 */
    	public Image getImage_rote180(Image img)
    	{
    		int width = img.getWidth(null);
    		int height = img.getHeight(null);
    		BufferedImage newImg = new BufferedImage(width, height, 1);
    		Graphics g = newImg.getGraphics();
    		g.drawImage(img, 0, 0, width, height, width, height, 0, 0, null);
    		g.dispose();
    		return newImg;
    	}
    	
    	/**
    	 * 顺时针转270
    	 * @param img
    	 * @return
    	 */
    	public Image getImage_rote270(Image img)
    	{
    		int width = img.getWidth(null);
    		int height = img.getHeight(null);
    		BufferedImage newImg = new BufferedImage(height, width, 1);
    		Graphics g = newImg.getGraphics();
    		Graphics2D g2d = (Graphics2D) g;
    		g2d.rotate(Math.toRadians(-90), 0, 0);
    		g2d.drawImage(img, -width, 0, width, height,  null);
    		g2d.dispose();
    		return newImg;
    	}
    	
    	
    	
    	
    	/**
    	 * 关于y=x翻转
    	 * @param srcImg
    	 * @return
    	 */
    	public Image getImage_FLIP_YISX(Image srcImg)
    	{
    		int width = srcImg.getWidth(null);
    		int height = srcImg.getHeight(null);
    		BufferedImage result = new BufferedImage(height, width, 1);
    		Graphics g = result.getGraphics();
    		Graphics2D g2d = (Graphics2D) g;
    		AffineTransform affineTransform = new AffineTransform(0, -1, -1, 0, height, width);
    		AffineTransformOp affineTransformOp = new AffineTransformOp(affineTransform, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
    		affineTransformOp.filter(getClone(srcImg), result);
    		g2d.dispose();
    		return result;
    	}
    	
    	
    	/**
    	 * 关于y=-x翻转
    	 * @param srcImg
    	 * @return
    	 */
    	public Image getImage_FLIP_YISFUX(Image srcImg)
    	{
    		int width = srcImg.getWidth(null);
    		int height = srcImg.getHeight(null);
    		BufferedImage result = new BufferedImage(height, width, 1);
    		Graphics g = result.getGraphics();
    		Graphics2D g2d = (Graphics2D) g;
    		AffineTransform affineTransform = new AffineTransform(0, 1, 1, 0, 0, 0);
    		AffineTransformOp affineTransformOp = new AffineTransformOp(affineTransform, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
    		affineTransformOp.filter(getClone(srcImg), result);
    		g2d.dispose();
    		return result;
    	}
    	
    	
    	
    	/**
    	 * 得到克隆图像
    	 * @param srcImg
    	 * @return
    	 */
    	public BufferedImage getClone(Image srcImg)
    	{
    		int width = srcImg.getWidth(null);
    		int height = srcImg.getHeight(null);
    		BufferedImage result = new BufferedImage(width, height, 1);
    		Graphics g = result.getGraphics();
    		g.drawImage(srcImg, 0, 0, width, height, 0, 0, width, height,null);
    		g.dispose();
    		return result;
    	}
    
  • 相关阅读:
    【C/C++】散列/算法笔记4.2
    【C/C++】PAT A1025 Ranking/算法笔记
    【科研工具】CAJViewer的一些操作
    【科研工具】知云-外文文献翻译神器
    【科研工具】流程图软件Visio Pro 2019 详细安装破解教程
    【Word】自动化参考文献-交叉引用
    【Matlab】线性调频信号LFM 仿真
    不是人人都懂的学习要点
    linux的那些事
    从一个男人身上看出他的修养和抱负
  • 原文地址:https://www.cnblogs.com/chaohi/p/1999473.html
Copyright © 2011-2022 走看看