Last active
December 26, 2016 10:42
-
-
Save LenKIM/238b8f95d5854a5bf7e56cc2caec6a3b to your computer and use it in GitHub Desktop.
[android] BitmapToDrawable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//비트맵을 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