I have tried looking at the SUN Tutorials on using TexturePaint and loading images into a BufferedImage object and then using that to form the TexturePaint object. None of this has worked for me, and its not really very intuitive. One would think that you could do: TexturePaint one = new TexturePaint("filepath.jpg"); and that Java could handle it. Shown below is my test code that isn't working right now.
Toolkit toolkit = Toolkit.getDefaultToolkit();
Image img = toolkit.getImage("sandtexture.jpg");
BufferedImage sandTexture = new BufferedImage(20, 20, BufferedImage.TYPE_INT_RGB);
Graphics2D writeImage = sandTexture.createGraphics();
writeImage.drawImage(img, 0, 0, this);
Rectangle r = new Rectangle(0,0, 20, 20);
TexturePaint sand = new TexturePaint(sandTexture, r);
g2 is a Graphics 2D Object.
sandArea is a GeneralPath polygon object.
This code is in my public void paint(Graphics g) method.
This code is in a class that extends JFrame, not JApplet - which is why I could not use the built-in getImage methods of JApplet.
Any suggestions on why this produces a "black screen" where the texture should be would be appreciated. The only thing I can figure is that the problem might be with the off-screen buffer size of my image (20, 20). The image itself has dimensions much higher, do I need to do a scale transform before loading it? Also, the writeImage.drawImage() method has parameters that don't seem to make sense. The last parameter (I have set to this) is for a Transform operation I believe. I set it to this because a website with sample code did it that way.