• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps is android supports auto scaling of images

hai guys,

i am developing a game. minimum screen resolution that it should support is 240 X 320 for above screen resolutions
like 320 X 480 etc the images should auto scale. how can i achieve it.
 
This is not auto detection, but I wrote a small function that returns a scaled bitmap based on a max width and height.

private Bitmap resizeImage( final Bitmap image, final int maxWidth, final int maxHeight ) {
final Bitmap resizedImage;
int imageHeight = image.getHeight();
if ( imageHeight > maxHeight )
imageHeight = maxHeight;
int imageWidth = (imageHeight*image.getWidth()) / image.getHeight();
if ( imageWidth > maxWidth ) {
imageWidth = maxWidth;
imageHeight = (imageWidth*image.getHeight()) / image.getWidth();
}
resizedImage = Bitmap.createScaledBitmap( image, imageWidth, imageHeight, true);
return resizedImage;
}
 
Back
Top Bottom