2010-12-22 7 views
1

내가 뭐하는 거지입니다 이미지 ID에서 :안드로이드 : 얻기 바이트 [] 여기

onActivityResult를, 나는 텐트에서 데이터를 얻을.

data.getData().getLastPathSegment(); 

지금 내가 바이트 [] imageData의 내가 서버에 이미지를 업로드 할 수 있습니다 얻기 위해이 이미지의 ID를 사용하려면 :

Intent intent = new Intent("android.media.action.IMAGE_CAPTURE"); 
startActivityForResult(intent, TAKE_PICTURE); 

이 코드는 이미지 ID를 가져옵니다.

어떻게 해결할 수 있습니까?

답변

1
Uri selectedImageUri = data.getData(); 

String[] projection = { MediaStore.Images.Media.DATA }; 
Cursor cursor = managedQuery(selectedImageUri, projection, null, null, null); 
cursor.moveToFirst(); 
selectedImagePath = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA)); 
cursor.close(); 

try 
{ 
    File myFile = new File(selectedImagePath); 
    int filelenghth=(int)myFile.length(); 
    byte [] mybytearray = new byte [filelenghth]; 
    BufferedInputStream bis1 = new BufferedInputStream(new FileInputStream(myFile)); 

    bis1.read(mybytearray,0,mybytearray.length); 

    dos.write(mybytearray,0,mybytearray.length); // write the array to the data output stream 
                // or whatever else you want to do with it 
    finish(); 
} 
catch(Exception e) 
{ 
    e.printStackTrace(); 
} 
+0

감사 Abhishek :

는 HTTP 포스트 코드에 대한 SO에서 다음 참조를 참조하십시오. 이것은 나에게 많은 도움이된다. –

0

data.getData()는 사용자의 이미지 URI를 반환합니다. (데이터를 확인! = 먼저 null!)

그러면 서버에 http 게시를 수행하면됩니다. Sending images using Http Post