I have an off screen BufferedImage
that too large to be displayed all at once. So I'm using getSubimage
to draw part of the entire image. I'm wondering if using setClip
on the Graphics
would use less resources. The docs say that "Rendering operations have no effect outside of the clipping area". How much of a difference would there be if I used a clip verses not using a clip?
When you set a clip on a Graphics
object – for example a Rectangle(0, 0, 100, 100)
–
and then draw an image with that same Graphics
object
– for example an image sized 300x300 –
the part of the image that lies outside of the clip is omitted. Only the top left 100x100 corner of the example would be drawn.
The main advantage to this is, that it speeds up the drawing process a lot. I'm not quite sure about how it makes it faster though; as a matter of fact I was looking this up right now.
In any case, I have found this to be very handy in designing full screen games. The more efficient you make your clips that draw to the screen, the smoother your game runs. When nothing is updating the screen components for a while, the clip stays empty, drawing nothing and leaving resources for game logic.