달력

6

« 2025/6 »

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
728x90
반응형
Drawable 이미지 저장하기 Android

2010/06/12 17:29

복사 http://blog.naver.com/lowmans/100107136246

얼마전 Drawable 이미지를 저장해야 하는 상황이 생겼다..

쉽게만 생각했었는데 막상 파일로 저장을 위해서는 여러가지 이슈들이 많이 있었다..

먼저 Drawable 이미지를 비트맵으로 바꾸어야 했는데 api가 없어서 구글링에서 알아본 결과

drawable / bitmap 이 가지고 있는 canvas 를 이용한 방법으로 해결한 예제를 보고 해결하였다..

또한 비트맵 생성시 이미지 사이즈가 문제가 되었는데.. drawable 이미지 크기를 가져오는건 api 를 찾아서 해결하였고

저장된 파일 이름을 정하는 부분에서도 기존엔 토큰하여 사용했었는데 이번엔 indexOf ~ substring 을 사용하여 해결하였다

---------------------------------------------------------------------------------------------------------------------------
public String getPackageIconIamges(String name){
int end = 0;
int start = 0;
for (int i = 0; i < mPackageCount; i++) {
info = app.get(i);
if(name.equals(info.activityInfo.packageName)){
Drawable icon = info.activityInfo.loadIcon(mPackageManager);
mIconSize_w = icon.getIntrinsicWidth();
mIconSize_h = icon.getIntrinsicHeight();
mPackageIconImages = Bitmap.createBitmap(mIconSize_w, mIconSize_h, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(mPackageIconImages);
icon.setBounds(0, 0, mIconSize_w, mIconSize_h);
icon.draw(canvas);
try{
while(true){
end = name.indexOf(".", start);
if(end == -1)
break;
start = end + 1;
}
FileOutputStream out = new FileOutputStream(iconDirPath + "/" + name.substring(start, name.length()) + ".png");
if(out != null){
mPackageIconImages.compress(Bitmap.CompressFormat.PNG , 100, out);
}
}catch(IOException e){
Log.e(TAG , "getPackagIamge Error : " + e.getMessage());
}
return iconDirPath + name.substring(start, name.length()) + ".png";
}
}
return null;

 

728x90
반응형
:
Posted by mapagilove