1. Are you ready for the Galaxy S20? Here is everything we know so far!

Apps Resize drawable before draw

Discussion in 'Android Development' started by moap, Feb 18, 2011.

  1. moap

    moap Newbie
    Thread Starter

    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 (Text):
    1.  
    2. int value;
    3. Drawable drawable = context.getResources().getDrawable(R.drawable.black);
    4. Bitmap img = Bitmap.createBitmap(X_WIDTH, 50, Bitmap.Config.ARGB_8888);
    5. Canvas canvas = new Canvas(img);
    6. //resize drawable here according to screen width
    7. drawable.setBounds(-value * X_WIDTH, 0, -value * X_WIDTH + X_WIDTH*13, 50);
    8. drawable.draw(canvas);
    9.  
     

    Advertisement

  2. moap

    moap Newbie
    Thread Starter

    Here is my code working as i want :

    Code (Text):
    1.  
    2.  
    3. int value;
    4. Drawable drawable = context.getResources().getDrawable(R.drawable.black);
    5. Bitmap img = Bitmap.createBitmap(X_WIDTH, 50, Bitmap.Config.ARGB_8888);
    6. Canvas canvas = new Canvas(img);
    7. drawable = new ScaleDrawable(drawable, 0, X_WIDTH*13, 50).getDrawable();
    8. drawable.setBounds(-value * X_WIDTH, 0, -value * X_WIDTH + X_WIDTH*13, 50);
    9.  
     
Loading...

Share This Page

Loading...