我在Java的新的,我有一個問題想的圖像設置光標。我使用的是BufferedImage
和Graphics.drawImage
但它只能繪製圖像的顏色和不完整的png圖片。爲什麼當我將圖像設置爲光標時,它不起作用?
這裏是我的代碼:
/*The images List*/
iconsBet.add(ImageIO.read(getClass().getResource("/resources/ChipType"+ String.valueOf(maxChipBet+1) +".png")));
/*The images List*/
BufferedImage output = new BufferedImage(iconsBet.get(0).getWidth(), iconsBet.get(0).getHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics graphicsCursorIcon = output.getGraphics();
int count = 0;
for(BufferedImage icon : iconsBet)
{
graphicsCursorIcon.drawImage(icon, 0, count*10, null);
count++;
}
graphicsCursorIcon.dispose();
Toolkit toolkit = Toolkit.getDefaultToolkit();
Cursor c = toolkit.createCustomCursor(output , new Point(mainPanel.getX(), mainPanel.getY()), "img");
mainPanel.setCursor(c);
的圖像:This is one image from the group of images that I'm using
程序只畫一個紅圈,而不是PNG圖像。
我已經嘗試使用所有BufferedImage
類型,但仍然無法正常工作。 你能幫我解決這個問題嗎?我需要做些什麼才能使它工作?
在Windows上,你是限制爲32×32的光標大小 - 它可能已經改變,但在Windows 7下是這樣的話/ Java 7的 – MadProgrammer
您在彼此的頂部繪製圖像。 你確定他們有適當的透明度嗎? 可能是最後一張圖片完全覆蓋了之前的所有圖片。 –
1)爲了更好地幫助越早,張貼[MCVE]或[簡要,獨立的,正確的示例](http://www.sscce.org/)。 2)獲取圖像的一種方法是通過[本問答](http://stackoverflow.com/q/19209650/418556)中的圖像進行熱鏈接。儘管在這種情況下,您可能會熱插入問題中嵌入的圖像。 –