zoukankan      html  css  js  c++  java
  • java图片操作--生成与原图对称的图片

    java图片操作--生成与原图对称的图片

    package com.pay.common.util;
    
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    
    import javax.imageio.ImageIO;
    
    import org.apache.commons.io.IOUtils;
    
    public class ImageChange {
    
        public static void main(String[] args) throws Exception {
            // TODO Auto-generated method stub
            
            String path="F:\123.jpg";
            String desc ="f:\1234.jpg";
            FileInputStream in =new FileInputStream(new File(path));
            //读取图片
            BufferedImage bufImage = ImageIO.read(in);
            int height=bufImage.getHeight();
            int width=bufImage.getWidth();
            
            System.out.println(height);
            System.out.println(width);
            
             // 读取出图片的所有像素
            int[] rgbs = bufImage.getRGB(0, 0, width, height, null, 0, width);
    
            // 对图片的像素矩阵进行水平镜像
            for (int row = 0; row < height; row++) {
                for (int col = 0; col < width / 2; col++) {
                    int temp = rgbs[row * width + col];
                    rgbs[row * width + col] = rgbs[row * width + (width - 1 - col)];
                    rgbs[row * width + (width - 1 - col)] = temp;
                }
            }
            // 把水平镜像后的像素矩阵设置回 bufImage
            bufImage.setRGB(0, 0, width, height, rgbs, 0, width);
    
            // 把修改过的 bufImage 保存到本地
            ImageIO.write(bufImage, "JPEG", new File(desc));
        
    
            
        }
    
    }
    原创打造,多多指教
  • 相关阅读:
    c++的正则库 pcre
    http://alibench.com
    常用正则表达式,来自新浪微博的js
    mysql的反向
    字母汉子组合的验证码,包括实现看不清换一个的功能
    什么是Ajax
    做“时间日志”
    计划比目标还要重要!
    成功座右铭一
    建立组织
  • 原文地址:https://www.cnblogs.com/iscys/p/9514372.html
Copyright © 2011-2022 走看看