申し訳ありませんが、これはちょっとしたコードですが、ここで切り取るものはあまりありません。これは、イメージ (アルファベットのスプライト シート) を読み取り、それを個々の文字である小さなサブイメージに分割することになっています。キーを押すと対応する文字が画面に表示されますが、この部分は実際のサブイメージを作成するためのものです。
http://i.imgur.com/4I4uX.png (画像)
package typeandscreen;
(where the imports should be, i just cut them out to save space)
public class Font{
final int width = 78; //gives the dimensions of the image
final int height = 32;
final int rows = 4;
final int cols = 13;
BufferedImage letters[] = new BufferedImage[rows*cols]; //makes the array of
//subimages. rows*cols is
//the number of subimages
void test(){
try{
final BufferedImage totalImage = ImageIO.read(new File("ABCabcs.png"));
//loads the big image itself
この次の部分は、私を混乱させるものです。i と j は何のためにあるのですか?なぜそれらを加算したり乗算したりするのですか? この部分は、サブイメージがどれくらいの大きさでなければならないかを調べるためのものですよね? 行 * 列である 4 x 13 であってはなりませんか?
for(int i = 0; i < rows; i++){
for(int j = 0; j < cols; j++){
letters[(i * cols) + j] = totalImage.getSubimage(
j * width,
j * height,
width,
height
);
}
}
} catch(IOException e){
e.printStackTrace();
}
}
}
i と j が何をしているのかわかりません。ここで何が欠けていますか?