Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Convert a Drawable into Bitmap

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 640
    Comment on it

    Following method tells how to convert a drawable into bitmap

    // method to convert a drawable into Bitmap

      public static Bitmap drawableToBitmap (Drawable drawable) {
    // check if drawable is the instance of BitmapDrawable
        if (drawable instanceof BitmapDrawable) {
                return ((BitmapDrawable)drawable).getBitmap();
            }

        Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap); 
        drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
        drawable.draw(canvas);
    
        return bitmap;
    }
    

    Hope this method helps you.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: