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;
    	}
    
  • 相关阅读:
    招聘ASP.NET(C#)开发人员(已经截止,谢谢大家支持)
    VisualStudioCode开发Vue
    全局异常处理机制(Filter拦截器对比)
    工程师
    kubernetes(k8s)里面部署服务器集群并访问项目
    webpack 就是前端模块化打包工具
    Visual Studio Code配置C/C++开发环境
    docker和k8s(Kubernetes)是配套使用
    kettle 多表全删全插同步数据
    wireshark 抓HTTPS 的包 HTTPS = TLS + HTTP TLSv1.2 协议
  • 原文地址:https://www.cnblogs.com/chaohi/p/1999473.html
Copyright © 2011-2022 走看看