3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[java][android] bitmap drawable resource の変換いろいろ

Last updated at Posted at 2012-02-08
convertImage.java
//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();
}
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?