1

I was trying to convert this code from .NET to Java, but I couldn't convert these 4 lines. Please someone give me a suggestion how to convert this code:

this.pbSubSequence = (Image) new Bitmap(this.pbSubSequence.getWidth(),
                this.pbSubSequence.getHeight());
Image image = this.pbSubSequence.Image;
Graphics graphics = Graphics.FromImage(this.pbSubSequence.Image);

(pbSubSequence is a panel; I have four panels in this code and I have to draw sort of graph of ecg in all four of them which will be done by:

g.draw(new Line2D.Float(100f,100f,500f,500f)

(this line would run in a for loop)

Can someone help me write these lines in Java?

4

2 回答 2

1

要在 Java 中创建位图,请使用:BufferedImage()

要从此图像创建图形,请使用createGraphics()

我无法弄清楚你的 C# 代码的意义。

于 2012-12-07T18:38:11.247 回答
0

那天我尝试了这段代码,我几乎得到了我想要的

BufferedImage image=new BufferedImage(pbSubsequence.getWidth(), pbSubsequence.getHeight(), BufferedImage.TYPE_3BYTE_BGR);
            JLabel l=new JLabel(new ImageIcon(image));
            Graphics graphics = image.getGraphics();
            Graphics2D g = (Graphics2D) graphics;
            pbSubsequence.add(l); 

其中pbSubsequence是一个JPanel。所以我能够将代码从.net转换为java。仍然留下测试部分,所以不能确定答案是否正确。谢谢大家的帮助

于 2012-12-10T11:03:24.707 回答