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));
        
    
            
        }
    
    }
    原创打造,多多指教
  • 相关阅读:
    [Graph]Doubling Algorithm
    Luogu 3203 BZOJ 2002——弹飞绵羊
    BZOJ 1468——tree
    BZOJ 10628 Luogu 2633
    Mo's Algorithm
    bzoj1063: [Noi2008]道路设计
    bzoj1264: [AHOI2006]基因匹配Match
    bzoj1177: [Apio2009]Oil
    bzoj1260: [CQOI2007]涂色paint
    bzoj3674: 可持久化并查集加强版
  • 原文地址:https://www.cnblogs.com/iscys/p/9514372.html
Copyright © 2011-2022 走看看