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

Apps Resize drawable before draw

moap

Newbie
I have an image which i draw part of it with some condition.I want to resize drawable according to screen width then set bounds and draw image.Here is my code..

Code:
int value;
Drawable drawable = context.getResources().getDrawable(R.drawable.black);
Bitmap img = Bitmap.createBitmap(X_WIDTH, 50, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(img);
//resize drawable here according to screen width
drawable.setBounds(-value * X_WIDTH, 0, -value * X_WIDTH + X_WIDTH*13, 50);
drawable.draw(canvas);
 
Here is my code working as i want :

Code:
int value;
Drawable drawable = context.getResources().getDrawable(R.drawable.black);
Bitmap img = Bitmap.createBitmap(X_WIDTH, 50, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(img);
drawable = new ScaleDrawable(drawable, 0, X_WIDTH*13, 50).getDrawable();
drawable.setBounds(-value * X_WIDTH, 0, -value * X_WIDTH + X_WIDTH*13, 50);
 
Back
Top Bottom