imagedivision.java
来自「Java版拼图游戏」· Java 代码 · 共 33 行
JAVA
33 行
/*
* @(#)ImageDivision.java 1.0 03/08/22
* Copyright 2003 Entao Zhang, All rights reserved.
*/
import java.awt.*;
import java.awt.image.*;
import javax.swing.ImageIcon;
/**
* 图象分割算法之--长方形分割
*/
public class ImageDivision{
public ImageIcon[] Division(Image img,int x,int y,Component observer){
int w=img.getWidth(null);
int h=img.getHeight(null);
int cellw=w/x;
int cellh=h/y;
ImageIcon cell[]=new ImageIcon[x*y];
CropImageFilter cif;
FilteredImageSource fis;
int ci;
for (int j=0; j<y; j++) {
for (int i=0; i<x; i++) {
cif=new CropImageFilter(cellw*i,cellh*j,cellw,cellh);
fis=new FilteredImageSource(img.getSource(),cif);
ci=j*x+i;
cell[ci]=new ImageIcon(observer.createImage(fis));
}
}
return cell;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?