2017-04-23 2 views
0

아래 코드를 사용하여 비디오에서 서버로 업로드하려는 이미지를 가져오고 이미지가 거기에서 내 축소판 이미지로 나타납니다. 올바르게 작동하고 이미지가 다음에 표시됩니다. ImageView ...하지만 잘못되어있는 것은 SD 카드에 저장하지 않고 업로드 할 수 없다는 것입니다. SD 카드 URI가없는 서버에 직접 비트 맵 이미지를 업로드 할 수있는 방법이 있습니까?업로드하지 않음 비트 맵을 서버에 저장

내 코드 :

private void chooseVideo() { 
    Intent intent = new Intent(); 
    intent.setType("video/*"); 
    intent.setAction(Intent.ACTION_GET_CONTENT); 
    startActivityForResult(Intent.createChooser(intent, "Select a Video "), SELECT_VIDEO); 
} 

@Override 
public void onActivityResult(int requestCode, int resultCode, Intent data) { 
    if (resultCode == RESULT_OK) { 
     if (requestCode == SELECT_VIDEO) { 
      System.out.println("SELECT_VIDEO"); 
      selectedImageUri = data.getData(); 
      textView.setText(selectedPath); 

      bt = createVideoThumbnail(this, selectedImageUri); 
      iv_image.setImageBitmap(bt); 
     } 
    } 
} 

public static Bitmap createVideoThumbnail(Context context, Uri uri) { 
    Bitmap bitmap = null; 
    MediaMetadataRetriever retriever = new MediaMetadataRetriever(); 
    try { 
     retriever.setDataSource(context, uri); 
     bitmap = retriever.getFrameAtTime(-1); 
    } catch (RuntimeException ex) { 
     // Assume this is a corrupt video file. 
    } finally { 
     try { 
      retriever.release(); 
     } catch (RuntimeException ex) { 
      // Ignore failures while cleaning up. 
     } 
    } 
    return bitmap; 
} 

답변

0

는 base64로 다시 이미지로 다시 디코딩이

ByteArrayOutputStream stream = new ByteArrayOutputStream(); 

bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream); 
byte[] byte_arr = stream.toByteArray(); 
String image_str = Base64.encodeToString(byte_arr, Base64.DEFAULT); 

그런 다음 서버에 image_str를 POST보십시오.