切分和组合图片(二)

切分和组合图片(二)

组合步骤:
1. 初始化有多少小图片
2. 加载小图片到缓存中
3. 初始化大图片存储器
4. 组合小图片到大图片
5. 生成大图片文件

小图片源:


int rows = 4;   //初始化有小图片的数量 
        int cols = 4;  
        int chunks = rows * cols;  
  
        int chunkWidth, chunkHeight;  
        int type;  
        //读取图片文件 
        File[] imgFiles = new File[chunks];  
        for (int i = 0; i < chunks; i++) {  
            imgFiles[i] = new File("img" + i + ".jpg");  
        }  
  
       //缓存图片文件
        BufferedImage[] buffImages = new BufferedImage[chunks];  
        for (int i = 0; i < chunks; i++) {  
            buffImages[i] = ImageIO.read(imgFiles[i]);  
        }  
        type = buffImages[0].getType();  
        chunkWidth = buffImages[0].getWidth();  
        chunkHeight = buffImages[0].getHeight();  
  
        //初始化最终的图片缓存器
        BufferedImage finalImg = new BufferedImage(chunkWidth*cols, chunkHeight*rows, type);  
  
        int num = 0;  
        for (int i = 0; i < rows; i++) {  
            for (int j = 0; j < cols; j++) {  
                finalImg.createGraphics().drawImage(buffImages[num], chunkWidth * j, chunkHeight * i, null);  
                num++;  
            }  
        }  
        System.out.println("图片组合完");  
        ImageIO.write(finalImg, "jpeg", new File("b.jpg"));  
    }

生成的大图片:
















转载于:https://www.cnblogs.com/java20130722/archive/2013/05/10/3207251.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值