Alex Pardo
Alex Pardo

Reputation: 48

Bitmap not scaling to height Android

I have a 480 x 800 bitmap that I am using for a live wallpaper I am creating. When I test on the emulator the bitmap width and height scales fine but when I test on my Samsung S3 the bitmap width scales fine but the height is too short, shows black rectangle at the bottom. Is there a standard bitmap size I should be working with or is there something wrong in my code?:

    public void doDraw(Canvas c) {
    c.drawColor(Color.rgb(0,0,0)); // Clear the background.

    final int canvasWidth = getScreenWidth();
    final int canvasHeight = getScreenHeight();

    int imageWidth = mBitmap.getWidth();
    int imageHeight = mBitmap.getHeight();

    float scaleFactor = Math.min( (float)canvasWidth / imageWidth, 
                                  (float)canvasHeight / imageHeight );
    Bitmap scaled = Bitmap.createScaledBitmap(  mBitmap, 
                                                (int)(scaleFactor * imageWidth), 
                                                (int)(scaleFactor * imageHeight), 
                                                true );
    c.drawBitmap(scaled, 0, 0, null);

Upvotes: 1

Views: 124

Answers (1)

Nick
Nick

Reputation: 6385

I think you want Math.max() instead of Math.min()

Upvotes: 1

Related Questions