Faster drawing

I found Onyx’s code about chopping up a large imgae and into BufferedImages…real nice.

but
Which would be faster?

Method 1: (isnt this accelerated?)


      public BufferedImage getMsgBox() {
            //BufferedImage bi = getBaseBI();
            BufferedImage bi = new BufferedImage(boxWidth,75,Transparency.BITMASK);
            Graphics2D g = bi.createGraphics();
            int y = 20;
            g.setColor(Color.white);
            for(int i = 0;i<10;i++) {
                  g.drawString("Hi all!" + i, 10,y);
                  y+=13;
            }
            g.dispose();
            //bi = applyMask(bi, Color.black);
            return bi;
      }

Then somewhere in main loop


g.drawImage(getMsgBox(), 400,10, null);

Method 2:


      public void getMsgBox(Graphics2D g) {
              int y = 20;
            for(int i = 0;i<10;i++) {
                  g.setColor(msg.color());
                  g.drawString("Hi all"+i, 10, y);
                  y+=13;
            }      
      }

Then somewhere in main loop


getMsgBox(g);

My guess would be neither since I am calling a g.drawString,Rect,Oval or what have you, in both methods. ?

well, you don’t want to be creating the BufferedImage each time you call the function.
Pre-rasterize whatever you want to draw, onto a managed BufferedImage, then draw that to the screen instead.
(Assuming what you want to draw doesn’t change)

what I want to draw may change as it will be a menu system that appears when you click on a target. Thanks