1
我在Java中有一定的code,我試圖找到C#。 '我的問題到目前爲止是'方法油漆(圖形g)'。相當新的編程和仍然學習,我有點不知道如何正確地「轉換」此方法到C#。我的代碼現在看起來像this。C#的特定Java代碼
而且,這裏的Java方法不休息之類的:
public void paint(Graphics g) {
if (g == null)
throw new NullPointerException();
if (offscreenBuffer == null){
offscreenBuffer = createImage(this.getWidth(), this.getHeight());
offscreenGraphics = offscreenBuffer.getGraphics();
}
for (int x = 0; x < widthInCharacters; x++) {
for (int y = 0; y < heightInCharacters; y++) {
if (oldBackgroundColors[x][y] == backgroundColors[x][y]
&& oldForegroundColors[x][y] == foregroundColors[x][y]
&& oldChars[x][y] == chars[x][y])
continue;
Color bg = backgroundColors[x][y];
Color fg = foregroundColors[x][y];
LookupOp op = setColors(bg, fg);
BufferedImage img = op.filter(glyphs[chars[x][y]], null);
offscreenGraphics.drawImage(img, x * charWidth, y * charHeight, null);
oldBackgroundColors[x][y] = backgroundColors[x][y];
oldForegroundColors[x][y] = foregroundColors[x][y];
oldChars[x][y] = chars[x][y];
}
}
g.drawImage(offscreenBuffer,0,0,this);
}
謝謝,這已經幫了我很多。然而,如果你能幫我弄清楚C#中這段代碼的正確語法是什麼,我想我可以通過自己來判斷其餘部分: 'private Image offscreenBuffer; private graphics offscreenGraphics; ... 如果(offscreenBuffer == NULL){ offscreenBuffer =的createImage(this.getWidth(),this.getHeight()); offscreenGraphics = offscreenBuffer.getGraphics(); }' – Skyswimsky
而且,雖然它與我的問題無關,但評論中是否沒有可用的換行符? – Skyswimsky
'offScreenBuffer = createImage(this.Width,this.Height);''offscreenGraphics = Graphics.FromImage(offScreenBuffer);'不,在這裏評論中沒有允許線路剎車。而且,如果您的問題得到解答,請相應標記。 –