Android – How to set size of the image

android

I have splash.png and want that this image take all place on the screen like fitXY for ImageView. splash.png has sizes 480×767.

What does I must to change in my code?

public class BitmapConfigView extends LinearLayout {
private Bitmap mImage;
private Paint mPaint = new Paint();

public BitmapConfigView(Context context) {
    super(context);

    BitmapFactory.Options opts = new BitmapFactory.Options();
    opts.inPreferredConfig = Bitmap.Config.ARGB_8888;
    opts.inScaled = false;
    mImage = BitmapFactory.decodeResource( getResources(), R.drawable.splash, opts);

    mPaint.setDither(true);
    setWillNotDraw(false);
    setOrientation(VERTICAL);
    setGravity(Gravity.BOTTOM);
}

@Override
protected void onDraw(Canvas canvas) {
    canvas.drawBitmap(mImage, 0.0f, 0.0f, mPaint);
}
}

Best Answer

Scale the bitmap. This is what you're looking for:
android.graphics.Bitmap.createScaledBitmap