2013-02-25 2 views
1

안드로이드 에뮬레이터 SD 카드에서 이미지의 바이트 []를 어떻게 얻을 수 있습니까?SD 카드에서 바이트 [] 로의 이미지

여기에 내 현재 코드입니다 :

File f = new File("/mnt/sdcard/test.jpg"); 
ImageView mImgView1 = (ImageView)findViewById(R.id.iv); 
Bitmap bmp = BitmapFactory.decodeFile(f.getAbsolutePath()); 

내가 원하는 것은 내가이 작업을 수행 할 수있는 방법 이미지의 바이트 형식입니까?

답변

4

ByteArrayOutputStream 만들기 다음 compress() 방법 때문에 비트 맵의 ​​내용이 ByteArrayOutputStream에 전달됩니다 Bitmap의 전화 byte[]

public byte[] bitmapToByteArray(Bitmap b) 
{ 
    ByteArrayOutputStream stream = new ByteArrayOutputStream(); 
    b.compress(Bitmap.CompressFormat.PNG, 100, stream); 
    byte[] byteArray = stream.toByteArray(); 
    return byteArray; 
} 
로 변환

신청하려면

Bitmap bmp = BitmapFactory.decodeFile(file.getAbsolutePath()); 

byte[] bitmapBytes = bitmapToByteArray(bmp); 
0

당신처럼 [] 바이트 비트 맵을 변환 할 수 있습니다

String imageInSD = Environment.getExternalStorageDirectory().getAbsolutePath() +"/Folder/" + filename + ".PNG"; 
Bitmap bmp = BitmapFactory.decodeFile(imageInSD); 
ByteArrayOutputStream stream = new ByteArrayOutputStream(); 
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream); 
byte[] byteArray = stream.toByteArray(); 
관련 문제