我正嘗試通過將像素從舊位置複製到新座標來創建一個圖像,該圖像將邊框添加到Java上的現有圖像。到目前爲止,這是我所做的:將像素邊框添加到java中的圖像
public static NewPic border(NewPic p, int borderWidth, Pixel borderColor) {
int w = 2 * borderWidth;
int h = 2 * borderWidth;
Pixel[][] src = p.getBitmap();
Pixel[][] tgt = new Pixel[w][h];
for (int x = 0; x < w; x++) {
for (int y = 0; y < h; y++) {
if (x < borderWidth || x >= (w - borderWidth) ||
y < borderWidth)
tgt[x][y] = borderColor;
else
tgt[x][y] = src[x - borderWidth][y - borderWidth];
}
}
return new NewPic(tgt);
}
不知道爲什麼這不通過我的測試用例。任何人都可以提供任何指導嗎?
謝謝!
那麼以前對這個問題的回答有什麼問題?什麼是'NewPic'和'Pixel'?這些不是標準的Java類?哪兒來的呢? – MadProgrammer 2013-03-12 03:39:44