我正在尝试创建一个图像,通过将像素从旧位置复制到新坐标来为 Java 上的现有图像添加边框。到目前为止,这就是我所做的:
public static NewPic border (NewPic p, int borderWidth, Pixel borderColor) {
int w = p.getWidth();
int h = p.getHeight();
Pixel src[][] = p.getBitmap();
Pixel tgt[][] = new Pixel[h][w];
for (int x = 0; x < w; x++) {
for (int y = 0; y < h; y++) {
tgt[y][x + y + borderWidth] = src[x][y]; // this is probably where I a messing up
}
}
return new NewPic(tgt);
}
不确定我在评论的那一行做错了什么。我是 Java 新手。有人可以给我一些指导吗?