2011. 5. 20. 12:19 안드로이드

프로젝트 bin폴더의 resources.ap_ 파일을 삭제하고

프로젝트 F5누르고

다시 컴파일 하면 문제없이 ASSETS파일을 읽을 수있습니다.

 

다음 예제는 ASSETS폴더에있는 PNG를 BYTE 배열로 읽어 BITMAP으로 변환해 쓰는 예제입니다.

public static Bitmap getBitmap(String filename)
 {
  byte buf[]= getdata(filename);
  Log.i("getBitmap","buf.length"+buf.length);
  return BitmapFactory.decodeByteArray(buf, 0, buf.length);
 }
  
 public static byte[] getdata( String filename) {
  int length;

  AssetManager assetManager
  = (AssetManager)Context.getAssets();

  try {
  
   InputStream is = assetManager.open(filename,
     AssetManager.ACCESS_BUFFER);
    long filesize = is.available();
   Log.i("getdata ","filesize->"+filesize);
   
   byte[] buffer = new byte[(int) filesize];
   is.read(buffer);
   is.close();

   return buffer;
  } catch (IOException e) {
   e.printStackTrace();
  }
  return null;

 }

posted by 욱이다