안드로이드에서 비트맵을 드로잉 가능으로 변환하는 방법은 무엇입니까?
비트맵 이미지를 그리기 가능으로 변환하려면 어떻게 해야 합니까?
이것을 사용해 보세요. 그것은 변환합니다.Bitmap
이미지 타이핑 대상Drawable
Drawable d = new BitmapDrawable(getResources(), bitmap);
당신이 사용하고 싶은 것처럼 들립니다.
설명서에서 다음을 참조하십시오.
A
Drawable
비트맵을 래핑하고 타일링, 확장 또는 정렬할 수 있습니다.다음을 생성할 수 있습니다.BitmapDrawable
파일 경로, 입력 스트림, XML 확장을 통해 또는 에서Bitmap
물건.
비트맵을 변환할 때 크기 조정이 잘못되는 문제가 많이 발생함BitmapDrawable
일반적인 변환 방법은 다음과 같습니다.
Drawable d = new BitmapDrawable(getResources(), bitmap);
다음을 제외하고는Resources reference
,그bitmap
정확하게 스케일링해도 제대로 렌더링되지 않을 수 있습니다.여기에는 많은 질문들이 있는데, 이 방법을 사용하면 간단히 해결될 수 있습니다.bitmap
논쟁.
비트맵 그리기 가능한 공식 문서
다음은 비트맵을 그리기 가능으로 변환하는 방법에 대한 샘플입니다.
Bitmap bitmap;
//Convert bitmap to drawable
Drawable drawable = new BitmapDrawable(getResources(), bitmap);
imageView.setImageDrawable(drawable);
컨텍스트와 함께 사용했습니다.
//Convert bitmap to drawable
Drawable drawable = new BitmapDrawable(context.getResources(), bitmap);
그리기 가능한 비트맵:
Drawable mDrawable = new BitmapDrawable(getResources(), bitmap);
// mImageView.setDrawable(mDrawable);
비트맵으로 그리기 가능:
Bitmap mIcon = BitmapFactory.decodeResource(context.getResources(),R.drawable.icon_resource);
// mImageView.setImageBitmap(mIcon);
비트맵 이미지가 있고 그리기 가능한 이미지로 사용하려면 다음과 같이 하십시오.
Bitmap contact_pic; //a picture to show in drawable
drawable = new BitmapDrawable(contact_pic);
이렇게 하면 됩니다.
private void setImg(ImageView mImageView, Bitmap bitmap) {
Drawable mDrawable = new BitmapDrawable(getResources(), bitmap);
mImageView.setDrawable(mDrawable);
}
여기 또 다른 것이 있습니다.
Drawable drawable = RoundedBitmapDrawableFactory.create(context.getResources(), bitmap);
Kotlin 사용자의 경우:
코틀린은 변환 기능을 가지고 있습니다.Bitmap
로.BitmapDrawable
:
Bitmap.toDrawable(resources)
코드를 사용하여 스케치웨어 앱에서 그릴 수 있는 은밀한 비트맵
android.graphics.drawable.BitmapDrawable d = new android.graphics.drawable.BitmapDrawable(getResources(), bitmap);
언급URL : https://stackoverflow.com/questions/2415619/how-to-convert-a-bitmap-to-drawable-in-android
'programing' 카테고리의 다른 글
MockMvc, RestAssured 및 TestRestTemplate의 차이점은 무엇입니까? (0) | 2023.06.30 |
---|---|
복합 키를 사용하여 WHERE_IN 쿼리를 수행하시겠습니까? (0) | 2023.06.30 |
git 확장명이 없는 이진 파일 무시 (0) | 2023.06.25 |
검은색 포맷터 - 특정 다중 라인 코드 무시 (0) | 2023.06.25 |
.NET 응용 프로그램의 불규칙한 잘못된 보기 상태 문제 (0) | 2023.06.25 |