我目前有一個一維雙陣列,其中包含50個不同的點,意思是間隔1分開。我需要通過圖像中的線條來繪製和連接這些點。目前正在製作PNG圖像,如果我添加一行代碼就可以工作,但不知何故,這個循環會使整個圖像變成黑色。關於發生什麼問題的任何想法?使用Java中的點陣創建PNG圖像(總是顯示爲黑色)
BufferedImage bi = new BufferedImage(50, 50, BufferedImage.TYPE_INT_ARGB);
Graphics2D ig2 = bi.createGraphics();
ig2.setBackground(Color.white);
ig2.setColor(Color.red);
for(int i = 0; i < 49; i++){
Shape line = new Line2D.Double(i,finalpoints[i],i+1,finalpoints[i+1]);
ig2.draw(line);
}
//Export the result to a file
try {
ImageIO.write(bi, "PNG", new File("C://Users/vince/Desktop/heightmap.png"));
} catch (IOException e) {
System.out.println("There was an error writing the image to file");
}
是你的所有在你爲圖像設置的10x10尺寸內的點? – iestync
它實際上是一個50x50尺寸的圖像。尺寸不會改變輸出。 –
'終點'數組中的值是什麼? –