IT

드로어 블 리소스 이미지를 비트 맵으로 변환

lottoking 2020. 5. 27. 07:43
반응형

드로어 블 리소스 이미지를 비트 맵으로 변환


Notification.Builder.setLargeIcon(bitmap)비트 맵 이미지 를 사용하는 것을 사용하려고합니다 . 드로어 블 폴더에 사용하려는 이미지가 있는데이를 비트 맵으로 어떻게 변환합니까?


당신은 아마 그렇 Notification.Builder.setLargeIcon(Bitmap)습니까? :)

Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.large_icon);
notBuilder.setLargeIcon(largeIcon);

이것은 리소스 이미지를 Android로 변환하는 훌륭한 방법입니다 Bitmap.


Drawable myDrawable = getResources().getDrawable(R.drawable.logo);
Bitmap myLogo = ((BitmapDrawable) myDrawable).getBitmap();

API 22 getResources().getDrawable()는 더 이상 사용되지 않으므로 다음 솔루션을 사용할 수 있습니다.

Drawable vectorDrawable = VectorDrawableCompat.create(getResources(), R.drawable.logo,  getContext().getTheme());
Bitmap myLogo = ((BitmapDrawable) vectorDrawable).getBitmap();

Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.my_drawable);

Context당신의 현재가 될 수 있습니다 Activity.


안드로이드에서 Drawable 리소스를 비트 맵으로 변환하는 또 다른 방법은 다음과 같습니다.

Drawable drawable = getResources().getDrawable(R.drawable.input);
Bitmap bitmap = ((BitmapDrawable)drawable).getBitmap();


먼저 비트 맵 이미지 생성

Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.image);

이제 Notification Builder Icon에서 비트 맵을 설정합니다 ...

Notification.Builder.setLargeIcon(bmp);

에서 res/drawable폴더,

1. 새로운을 만듭니다 Drawable Resources.

2. 파일 이름을 입력하십시오.

res/drawable폴더 안에 새로운 파일이 생성됩니다 .

새로 작성된 파일 내에서이 코드를 바꾸고 ic_action_back드로어 블 파일 이름으로 바꾸 십시오.

<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/ic_action_back"
    android:tint="@color/color_primary_text" />

이제 리소스 ID와 함께 사용할 수 있습니다 R.id.filename.

참고 URL : https://stackoverflow.com/questions/8717333/converting-drawable-resource-image-into-bitmap

반응형