title: How do I build an Image from multiple smaller Images
body: <p>So I am making this adventure/progression game and for the font I am using tiles from a spriteSheet (each tile is a letter) which I will use for many different purposes, and I can't figure out why my program is returning a black Image instead of an Image built from smaller Images (each containing a letter). The program works when I return the <strong>scaledImage</strong> Image but that only returns a single letter. What is supposed to happen is I divide the word in a letter and use a <strong>BufferedImage</strong> and <strong>Graphics2D</strong> to get the matching letter from the spriteSheet, that part works, but when I draw it to the Buffered Image, it returns a black Image.</p>
  <pre><code>BufferedImage spriteSheet;
      String[] alphabet = { &quot;a&quot;, &quot;b&quot;, &quot;c&quot;, &quot;d&quot;, &quot;e&quot;, &quot;f&quot;, &quot;g&quot;, &quot;h&quot;, &quot;i&quot;, &quot;j&quot;, &quot;k&quot;, &quot;l&quot;, &quot;m&quot;, &quot;n&quot;, &quot;o&quot;, &quot;p&quot;, &quot;q&quot;, &quot;r&quot;, &quot;s&quot;,
              &quot;t&quot;, &quot;u&quot;, &quot;v&quot;, &quot;w&quot;, &quot;x&quot;, &quot;y&quot;, &quot;z&quot;, &quot; &quot; };
  
  public ImageIcon getWord(String word, int x, int size) throws IOException {
  
          String tempLetter;
          try {
              spriteSheet = ImageIO.read(new File(&quot;img/SpriteSheet.png&quot;));
          } catch (IOException e) {
              e.printStackTrace();
          }
          Image testImage = null;
  
          BufferedImage bi = new BufferedImage(size * word.length(), size, BufferedImage.TYPE_INT_RGB);
  
          Graphics2D wordImage = bi.createGraphics();
          Image subImage;
          Image scaledImage;
          
  
          for (int l = 0; l &lt; word.length(); l++) {
              tempLetter = word.substring(l, l + 1);
              
              for (int i = 0; i &lt; alphabet.length; i++) {
  
                  if (tempLetter.equalsIgnoreCase(alphabet[i])) {
                       subImage = spriteSheet.getSubimage(2 + (2 * i) + (i * 200), 2, 200, 200);
                       scaledImage = subImage.getScaledInstance(size, size, Image.SCALE_DEFAULT);
                      wordImage.drawImage(scaledImage, l*size, 0, null);
                      testImage = scaledImage;
                  } else {
                      continue;
                  }
  
              }
          }
  
          wordImage.dispose();
  
          File wordFile = new File(&quot;img/word.png&quot;);
          ImageIO.write(bi, &quot;png&quot;, wordFile);
          ImageIcon ic = new ImageIcon(&quot;img/word.png&quot;);
          wordFile.delete();
  
          return ic;
      }
  </code></pre>
  <p>This is how I call the method:</p>
  <pre><code>   JButton play = new JButton();
  
              play.setBounds(300, 300, 600, 150);  
              play.setIcon(sc.getWord(&quot;play&quot;, 600, 150)); 
  p.add(play);
  f.add(p);
  </code></pre>