2014-10-30 3 views
0

loopj로 이미지를 업로드하고 있습니다.서버에 업로드하기 전에 Picasso로 이미지 크기를 조정하는 방법은 무엇입니까?

params.put("file_"+key+"", new File(String.valueOf(value.getOriginalPath()))); 

업로드하기 전에 이미지의 크기를 조정하고 싶습니다. 크기를 조정하지 않고 "즉시"이미지 크기를 조정할 수 있습니까?> SD로 저장?> 업로드 하시겠습니까? 메신저 메모리 크기 조정 및 업로드 - InputStream?

감사합니다.

답변

6

예 : 을 사용할 수 있습니다. 여기

어떻게 이것에 대해 : How to Resize a Bitmap in Android?

편집 - 서버에 비트 맵을 보내기

는 대신 모든 픽셀 들어, PNG 또는 JPEG과 같은 압축되지 않는 메모리의 비트 맵이 상당히 크다고 당신은 3 필요 또는 심지어 4 바이트의 메모리. 따라서 해당 비트 맵을 예를 들어로 변환해야합니다. 업로드하기 전에 PNG. Bitmap.compress(...) 메서드를 사용하면 압축 된 이미지를 쓰는 데 OutputStream이 필요합니다. 업로드하기 전에 이미지를 SD 카드에 저장하지 않으려면 ByteArrayOutputStream을 사용하여 압축 된 이미지를 메모리에 보관할 수 있습니다.

다음으로 작성된 바이트에 ByteArrayInputStream을 첨부하여 loopj에 전달할 수 있습니다.

코드 이것은과 같이 보일 것이다 :

ByteArrayOutputStream outStream = new ByteArrayOutputStream(); 
b.compress(Bitmap.CompressFormat.PNG, quality, outStream); 
ByteArrayInputStream inStream = new ByteArrayInputStream(outStream.toByteArray()); 

/* ...and then pass inStream loopj */ 
+0

확인 나 비트 맵 이미지를 'B = BitmapFactory.decodeByteArray (imageAsBytes, 0, imageAsBytes.length) profileImage.setImageBitmap (Bitmap.createScaledBitmap 스케일링 (b, 120, 120, false)); '어떻게 loopj 매개 변수에 넣을 수 있습니까? 그것은 InputStream, File, ByteArrayInputStream을 지원합니다. – SERG

+0

답변에 대한 예제를 추가했습니다. – Ridcully

+0

은 OutOfMemoryError가'AsyncHttpClient client = new AsyncHttpClient();에 있습니다. client.post (여기))'서버에 사진을 업로드하는 간단하고 올바른 방법이 있습니까? – SERG

0
Target mTarget = new Target() { 
    @Override 
    public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom loadedFrom) { 
     Log.d("!!!!!",">>>>>>>>>>>>"); 
     SaveImage.SaveImageFromBitmap(bitmap); 
    } 

    @Override 
    public void onBitmapFailed(Drawable drawable) { 
     Log.d("!!!!!","--------"); 
    } 

    @Override 
    public void onPrepareLoad(Drawable drawable) { 

    } 
}; 
File file = new File(value.getOriginalPathString()); 
Picasso.with(AddSpa.this).load(file).resize(800,0).into(mTarget);