该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import java.awt.image.*;
import javax.imageio.*;
class ImageSplit{
JFrame frm ;
ImageSplit(JFrame frm){
this.frm = frm;
}
public BufferedImage splitImg(String filename, int row, int col, int dx, int dy){
BufferedImage bkimg; Graphics2D bkdc; Image srcimg;int iw,ih;
try{
srcimg = ImageIO.read(new File(filename));
iw = srcimg.getWidth(frm); ih = srcimg.getHeight(frm);
bkimg = new BufferedImage( iw + row * dx, ih + col * dy, 1);
bkdc = (Graphics2D) bkimg.getGraphics();
int wd = iw/row, hd = ih/col;
for(int i=0;i
for(int j=0;j
int xp = i*wd, yp = j*hd, sx = xp+i*dx, sy = yp+j*dy;
bkdc.drawImage(srcimg, sx,sy,sx+wd,sy+hd, xp,yp,xp+wd,yp+hd,null);
}} return bkimg;
}catch(IOException err){}
return null;
}
}
class Blue2 extends JFrame implements ActionListener{
int width = 520, height = 420;
Image img1 = null;
Blue2(){
setBounds(100,100,width,height);
ImageSplit simg = new ImageSplit(this);
img1 = simg.splitImg("java1.jpg",4,4,10,10);
/*img1 = simg.splitImg(,);*/
setDefaultCloseOperation(3);
setVisible(true);
}
public void paint(Graphics mdc){
super.paint(mdc); /*显示出来*/
if(img1!=null) mdc.drawImage(img1,20,60,this);
}
public void actionPerformed(ActionEvent e){
}
public static void main(String[] ag){
new Blue2();
}
}