我在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)中的图像进行热链接。尽管在这种情况下,您可能会热插入问题中嵌入的图像。 –