drawImage() ... i can't get subimage

every time i try drawImage(img, dx, dy…), when I move my character it scales the map in and out, up and down, rather than moving that portion of the map.
I want to have a camera that follows the hero, and it works via bufferedimage.subImage, but that is freakishly slow. So in my main loop I have
offscreen.drawImage(map.paint(subImage), 0,0, this)
and my paint method should return a subimage of the big image.

      public Image paint(Image subImage)
      {      // Set the viewable portion of the canvas to the hero's coords
            
            if (cameraFollow){
            clipX=hero.x-320; clipY=hero.y-240; clipWidth=640; clipHeight=480;
            if (hero.x-320<=0)             clipX=0;
            else if (hero.x+320>=width)    clipX=width-640;
            if (hero.y-240<=0)             clipY=0;
            else if (hero.y+240>=height)   clipY=height-480;
          }
            
            canvas.setClip(clipX, clipY, clipWidth, clipHeight);;       
            canvas.drawImage(chip1,0,0, null);
            canvas.drawImage(hero.image,hero.x, hero.y, null);
            for (int i=0; i<sprites.size(); i++)
                  {thisSprite=(Sprite)sprites.get(i);
                   canvas.drawImage(thisSprite.image,thisSprite.x, thisSprite.y, null);}
            canvas.drawImage(chip2, 0,0,null);
            canvas.drawImage(subImage, 0,0,appWidth, appHeight, clipX, clipY, clipWidth, clipHeight, applet);
            return subImage;
            
      }

There are a lot of drawImage versions. You need the one with source and target “rects”.

However, it’s a bad idea to do so anyways. First of all the images are stored decompressed in ram. Using a single huge image means you’ll need s***loads of memory. Usually too much to fit into vram and you won’t get acceleration.

The background should be drawn with tiles. A map can be really really big this way and it’s fast too, because you only draw a bunch of tiles which are either fully or partially visible (as opposed to draw a gigantic image of which only a tiny fraction is visible).

The tile size should be power of 2. Usual sizes are 16x16 to 256x256. I suggest 32x32 (or 64x64) tiles. That size offers a good speed (amout of method calls) vs detail-variance compromise.

Oh and your rendering method should really render the visuals and not produce yet another image which is then drawn. It doesn’t make any sense to do so if you’re using BufferStrategy (and even with “manual” double buffering it would be a bit odd to do so).

Each frame get the graphics object, draw, dispose and show.

so should i save the bimage data into a 2d array of images?