Talk:How to Fit an Image to the Screen Size
This article discusses a common problem in Java ME, that of resizing images to fit different screen resolutions. The article demonstrates how to resize an image to be used as a background image for a Canvas. The default drawImage() method provided by the Graphics class does not allow the programmer to set width and height properties (as is possible in Java Standard Edition applications). The article demonstrates how to get around this by using the getRGB() method of the Image class. This allows access to the individual pixels (RGB = red, green blue) of the image. These are then stretched or compressed to create an image according to the dimensions of the screen in question. In this way, programmers can adjust for different screen sizes.
A couple of drawbacks should, however, be noted. Image resizing is processing intensive, and the performance of the code provided depends on the resolution of the original image. Furthermore, if the aspect ratio (width/height) of the screen in question does not match the original image, the result can look rather stretched or squashed. The use of images as backgrounds should also be avoided on devices where the phone can switch from portrait to landscape mode.