android source

drawable resource를 bitmap으로

리오파파 2023. 12. 17. 20:16

1. bitmap으로 전환

Drawable drawable = ContextCompat.getDrawable(context, drawableId);
Bitmap bitmap = Bitmap.createBitmap(xySize, xySize, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, xySize, xySize);
drawable.draw(canvas);
return bitmap;

 

2. drawable 이름 알아내기

public String getGame(int i) {
   String []ids = mContext.getString(R.mipmap.resourceId).split("/");
   String s = ids[ids.length-1];
   s = s.substring(0, 3);
   return s;
}

 

'android source ' 카테고리의 다른 글

imageview with rounded corner  (0) 2023.12.19
Google File Async Download  (0) 2023.12.17
phone vibrate  (0) 2023.12.17
Phone Metric 얻기  (0) 2023.12.17
bitmap <-> string  (0) 2023.12.17