Skip to content

Instantly share code, notes, and snippets.

@LenKIM
Last active December 26, 2016 10:42
Show Gist options
  • Save LenKIM/238b8f95d5854a5bf7e56cc2caec6a3b to your computer and use it in GitHub Desktop.
Save LenKIM/238b8f95d5854a5bf7e56cc2caec6a3b to your computer and use it in GitHub Desktop.
[android] BitmapToDrawable
//비트맵을 drawable로 변환하는 함수
public Drawable getDrawableFromBitmap(Bitmap bitmap){
Drawable drawable = new BitmapDrawable(bitmap);
return drawable;
}
//Drawable 을 Bitmap으로 변환하는 함수
public static Bitmap drawableToBitmap (Drawable drawable){
if (drawable instanceof BitmapDrawable){
return ((BitmapDrawable)drawable).getBitmap();
}
Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),drawable.getIntrinsicHeight(),
Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0,0,canvas.getWidth(),canvas.getHeight());
drawable.draw(canvas);
return bitmap;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment