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);'不,在这里评论中没有允许线路刹车。而且,如果您的问题得到解答,请相应标记。 –