Skip to content

Instantly share code, notes, and snippets.

@itoz
Created July 10, 2011 12:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itoz/1074518 to your computer and use it in GitHub Desktop.
Save itoz/1074518 to your computer and use it in GitHub Desktop.
java android bitmap drawableの変換いろいろ
//Resource → Bitmap
BitmapFactory.decodeResource(getResources(), R.drawable.icon);
//Resource → Drawable
getResources().getDrawable(R.drawable.icon);
/**
* BitmapをDrawableに変換
*
* @param bitmap
* @return BitmapDrawable
*/
public static BitmapDrawable convert(Bitmap bitmap)
{
return new BitmapDrawable(bitmap);
}
/**
* DrawableをBitmapに変換
*
* @param drawable
* @return Bitmap
*/
public static Bitmap convert(Drawable drawable)
{
return ((BitmapDrawable) drawable).getBitmap();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment