-
[UI] 이미지 관련Android/UI 2021. 7. 28. 11:19
기록용 메모장. 상시 추가될 예정
imageView.getDrawable();
//return Drawable(이미지뷰에 설정된) or null(이미지뷰에 설정된 Drawable이 없으면)BitmapDrawable (비트맵 파일) - 비트맵 그래픽 파일 .png .jpg .gif에 해당
imageView에서 가져온 Drawable이 BitmapDrawable이라면 Drawable은 BitmapDrawable으로 형변환이 가능
//ImageView에 설정된 Drawable에서 Bitmap 추출 private Bitmap bitmapFromDrawable(ImageView imageView) { Drawable drawable=imageView.getDrawable(); if (drawable == null) { printToast("ImageView에 설정된 Drawable이 없음"); return null; } Bitmap bitmap = null; if(!(drawable instanceof BitmapDrawable)){ printToast("Drawable이 BitmapDrawable이 아님"); return null; } BitmapDrawable bitmapDrawable=(BitmapDrawable)drawable; bitmap=bitmapDrawable.getBitmap(); if(bitmap ==null){ printToast("BitmapDrawable에서 Bitmap추출 오류"); return null; } return bitmap; }
//리소스 Drawable에서 Bitmap 추출 private Bitmap bitmapFromResource(){ return BitmapFactory.decodeResource(getResources(),R.drawable.test); }
https://codechacha.com/ko/convert-between-drawable-and-bitmap-in-android/
안드로이드 Drawable을 Bitmap으로, Bitmap을 Drawable로 변경하는 방법
Drawable을 Bitmap으로 변경하는 방법 및 Bitmap을 Drawable로 변환하는 방법을 소개합니다. 또한 AdaptiveIconDrawable을 Bitmap으로 변환하는 방법을 알아봅니다. 안드로이드의 리소스들은 기본적으로 Drawable
codechacha.com
Bitmap을 byte[]로
// convert from bitmap to byte array public byte[] getBytesFromBitmap(Bitmap bitmap) { ByteArrayOutputStream stream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream); //비트맵 데이터를 stream에 넣어주는 compress 메서드 byte[] byteArray=stream.toByteArray(); return byteArray; }
//get the base 64 string String imgString = Base64.encodeToString(getBytesFromBitmap(bitmap), Base64.NO_WRAP);
byte[]를 Bitmap으로
BitmapFactory.decodeByteArray(바이트 배열, 시작, 끝, 팩토리 옵션)
options로 bitmap스펙 확인
BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeByteArray(bytes, 0, bytes.length,options); int imageHeight = options.outHeight; int imageWidth = options.outWidth; String imageType = options.outMimeType;
imageView.setImageResource vs imageView.setImageBitmap
setImageResource는 density만큼 scale되서 설정된다.
setImageBitmap의 createScaledBitmap에 density만큼 scale시키면 같은 결과가 나타난다.
imageView.setImageResource(int resId) vs. imageView.setImageBitmap(Bitmap bitmap);
The image file is identical. Once it comes from the drawable and one from the file system. Here is the code.
stackoverflow.com
https://s2choco.tistory.com/18
[Android] Bitmap Compress Format (JPEG vs PNG vs WEBP)
안드로이드 앱을 개발하면서 이미지 파일을 다루는 일이 굉장히 흔하다. 안드로이드 앱에서 이미지 파일은 Bitmap을 이용해서 다루는데, Bitmap 객체를 이미지를 파일로 저장하고 싶을 때 Bitmap의 co
s2choco.tistory.com
https://developer.android.com/reference/android/graphics/Bitmap.CompressFormat#summary
Bitmap.CompressFormat | Android 개발자 | Android Developers
developer.android.com
안드로이드에서 createScaledBitmap의 마지막 매개변수 filter의 역할
android.graphics.Bitmap.createScaledBitmap의 정의를 보면 public static Bitmap createScaledBitmap (Bitmap src, int dstWidth, int dstHeight, boolean filter) 라고 filter가 있는데요. 이 값이 true이고 false이고의 차이가 뭔가요?
hashcode.co.kr
'Android > UI' 카테고리의 다른 글
[UI] 스타일과 테마 - 1 (0) 2021.09.24 [UI] Context Menu 사용법 (0) 2021.09.18 [UI] Touch Event (2) - 터치 이벤트의 시작과 끝 (0) 2021.09.16 [UI] Touch Event (1) - 터치 이벤트 전달 과정 (0) 2021.09.15 [UI] RecyclerView 공부 (0) 2021.07.31