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;
}
'안드로이드' 카테고리의 다른 글
안드로이드 apk 디컴파일(까보자) (0) | 2011.06.22 |
---|---|
안드로이드 소스 f3누르면 보이게 하는 방법(android.jar source 보이는 방법) (0) | 2011.06.20 |
android api demo 내용 (0) | 2011.05.20 |
MessageHandler (0) | 2011.04.21 |
Alert 다이얼로그 (0) | 2011.04.21 |