我在BufferedImage img
中有图像,我有Graphics2D g2
一个对象Player[][] matrixPlayer = new Player[800][800]
的双数组,现在,我希望将此数组(matrixPlayer
)打印到我的{{1}我怎么能这样做?
如何计算图像的比例?
BufferedImage img
比你们所有人。
编辑:
有两个文件(http://www.sendspace.com/filegroup/wwFs6z5VfqiVVdgkjejEWQ)
PLAYER:
int h = img.getHeight();
int w = img.getWidth();
for(int i = 0; i < 800; i++){
for (int j = 0; j < 800; j++) {
if(matrixPlayer[i][j]!=null)
///DRAW RECT on matrixPlayer[i][j].get(x); get(y);
}
}
主要课程
public class Player {
private int x;
private int y;
private final String name;
private final String nameVil;
private final String aliance;
public Player(String x, String y, String name, String nameVil, String aliance) {
this.x = Integer.parseInt(x);
this.y = Integer.parseInt(y);
this.name = name;
this.nameVil = nameVil;
this.aliance = aliance;
}
public void setX(int x) {
this.x = x;
}
public void setY(int y) {
this.y = y;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
public String getName() {
return name;
}
public String getNameVil() {
return nameVil;
}
public String getAliance() {
return aliance;
}
}
答案 0 :(得分:0)
计算缓冲图像与玩家位置之间的比率。
final double widthRatio = img.getWidth() / 800.0;
final double heighRatio = img.getHeight() / 800.0;
然后根据您的玩家位置将该比率多倍,以确定在何处绘制玩家。
final int drawX = (int) Math.round(player.getX() * widthRatio);
final int drawY = (int) Math.round(player.getY() * heightRatio);