2012-12-08 4 views
1

카메라에서 최대 해상도 (예 : 12mpx)로 큰 이미지를 게시해야합니다. 하지만 필자는 byteArrayInputStream을 게시하기 위해 파일 스트림을 디코딩 할 때 종종 OutOfMemoryError를 얻습니다. 큰 이미지를 게시하는 다른 방법이 있습니까?안드로이드에 Http post 고해상도 이미지

p.s. 이 사진을 표시하거나 크기를 조정할 필요가 없습니다.

HttpClient httpclient = new DefaultHttpClient(); 
HttpPost httppost = new HttpPost(url); 


MultipartEntity entity = new MultipartEntity(
HttpMultipartMode.BROWSER_COMPATIBLE); 
File file= new File(filePath); 
if(file.exists()) 
{ 
    entity.addPart("data", new FileBody(file)); 
} 

httppost.setEntity(entity); 
HttpResponse response = httpclient.execute(httppost); 

는 다중 엔티티를 사용하려면 다운로드 및 빌드에 httpmime-4.1.2.jar를 추가해야합니다 :

답변

2

예, MultipartEntity에 의해 이미지/파일을 게시 할 수 있습니다를, 샘플 스 니펫을 검색 할 수 있습니다 프로젝트의 경로.

2

당신이

0

그 다음 원본 이미지 형식으로 게시 파일 스트림에서 직접 데이터를 보낼 수 있다면 11에 동일한 API 레벨 이상을 사용하거나하는 경우 응용 프로그램 수준 android:largeHeap="true"에서 매니페스트에이 줄을 사용하십시오 :

FileInputStream imageIputStream = new FileInputStream(image_file); 

HttpURLConnection connection = (HttpURLConnection) url.openConnection(); 
connection.setRequestMethod("POST"); 

OutputStream out = connection.getOutputStream(); 

copyStream(imageIputStream, out); 

out.close(); 
imageIputStream.close(); 

copyStream 함수 :

static int copyStream(InputStream src, OutputStream dst) throws IOException 
{ 
    int read = 0; 
    int read_total = 0; 
    byte[] buf = new byte[1024 * 2]; 

    while ((read = src.read(buf)) != -1) 
    { 
     read_total += read; 
     dst.write(buf, 0, read); 
    } 

    return (read_total); 
}