Aung Aung Swe
Aung Aung Swe

Reputation: 63

How to set drawn Bitmap width and height

Please, I want to set size of my bitmap image. I searched it from stackover flow but I don't get it, I am dull.

public class Circle extends View{
float y=300 ;


public Circle(Context context) {
    super(context);
    // TODO Auto-generated constructor stub
}
protected void  onDraw(Canvas c){
    super.onDraw(c);

    Bitmap myBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
    c.drawBitmap(myBitmap,y,0,null);
    Bitmap myBitmap1 = BitmapFactory.decodeResource(getResources(),    R.drawable.ic_launcher);
    c.drawBitmap(myBitmap,y+100,0,null);
    invalidate();
}
} 

It appears the original size of the image but I want it to change upon different screen size. I already know how to change it upon different screens but I don't know yet is how to set bitmap size. (I am using API min-10) . Please Advice me !!

Upvotes: 1

Views: 88

Answers (1)

Daniel Conde Marin
Daniel Conde Marin

Reputation: 7742

You'll have to scale it:

mBitmap = Bitmap.createScaledBitmap(mBitmap, newWidth, newHeight, true);

Upvotes: 2

Related Questions