2013-01-14 4 views
1

카메라에서 가져온 사진을 base64 문자열로 서버에 보내려고합니다. 내 문제는 사진이 전화로 어떻게 든 손상된다는 것입니다.phonegap picture base64 android

나는 camera.getPicture의 success 함수 내에서 base64 문자열을 인쇄하기 위해 console.logs를 가지고 있는데, 문자열을 인쇄하고 이미지를 디코드 할 때마다 불완전한 것처럼 맨 위 부분 만 보여줍니다.

photo.capturePhoto = function(image_button_id) { 
     navigator.camera.getPicture(function(image) { 
      photo.onPhotoDataSuccess(image) 
     }, onFail, { 
      quality : 30, 
      destinationType: destinationType.DATA_URL, 
      correctOrientation : true 
     }); 
    } 

및 성공 기능 :

photo.onPhotoDataSuccess = function(image) { 
     console.log(image); //What this prints is an incomplete image when decoded 
    } 

이 코드에 어떤 문제가 여기에

내 코드? 당신은 이미지 품질을 높이기 위해 시도 할 수 http://www.freeformatter.com/base64-encoder.html enter image description here

내가 폰갭에게 2.2.0

답변

0

을 사용하고 있습니다 : 디코딩과 때

는 예를 들어 이미지입니다. 품질이 낮게 설정되어 있으면 안드로이드 폰에 문제가 있다는 것을 기억합니다. 나는 그것이 긴 총이지만 가치가있는 시도라는 것을 알고있다.

+0

이미 행운을 빕니다. (어쨌든 도와 줘서 고마워요. –

0

나는 console.log에 인쇄 할 수있는 문자 수에 대한 제한이 있다고 생각한다. 이 같은 이미지 태그의 소스로 데이터를 설정하면 어떻게됩니까 : 또한

function onSuccess(imageData) { 
    var image = document.getElementById('myImage'); 
    image.src = "data:image/jpeg;base64," + imageData; 
} 

, 당신은 파일에서 데이터를 작성하려고 할 수 있습니다.

+0

데이터를 배경으로 설정하고 완벽하게 작동합니다. 이미지 크기를 100x100으로 낮추면 모양이 완성됩니다. 그러나 크기를 늘리면 비트, 이미지가 손상된 것 같습니다. –

+0

크기를 늘리면 무엇을 의미합니까? –

0

내가 안드로이드에서 같은 문제에 직면 한 정확한 문제가 IS_ 내가 뭘 이미지 크기가 더 (2메가바이트 이상의 경우는이 Base64 & 해당로 이미지를 인코딩 할 때 ... &는 이미지 품질 & 카메라 품질에 따라 달라집니다, 2MP 또는 5MP 또는 8MP 카메라 일 수 있습니다) 다음 Base64로 전체 이미지를 변환하는 문제가 발생 ... 당신은 우려 이미지의 크기를 줄여야 만합니다! 나는

 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
     Bitmap mBitmap= new decodeFile("<PATH_OF_IMAGE_HERE>"); 
     mBitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos); 
     byte[] b = baos.toByteArray(); 
     int i=b.length; 
     String base64ImageString=android.util.Base64.encodeToString(b, 0, i, android.util.Base64.NO_WRAP); 

적절한 비트 맵으로 변환 내 오기 전
it_ 달성되는 Android code 작업 Base64로 이미지 문자열 줄이

나는이 다른 사람을 도움이되기를 바랍니다
 /** 
     *My Method that reduce the bitmap size. 
     */ 
     private Bitmap decodeFile(String fPath){ 

     //Decode image size 
     BitmapFactory.Options opts = new BitmapFactory.Options(); 
     //opts.inJustDecodeBounds = true; 
     opts.inDither=false;      //Disable Dithering mode 
     opts.inPurgeable=true;     //Tell to gc that whether it needs free memory, the Bitmap can be cleared 
     opts.inInputShareable=true;    //Which kind of reference will be used to recover the Bitmap data after being clear, when it will be used in the future 
     opts.inTempStorage=new byte[1024]; 

     BitmapFactory.decodeFile(fPath, opts); 

     //The new size we want to scale to 
     final int REQUIRED_SIZE=70;//or vary accoding to your need... 

     //Find the correct scale value. It should be the power of 2. 
     int scale=1; 
     while(opts.outWidth/scale/2>=REQUIRED_SIZE && opts.outHeight/scale/2>=REQUIRED_SIZE) 
      scale*=2; 

     //Decode with inSampleSize 
     opts.inSampleSize=scale; 

     return BitmapFactory.decodeFile(fPath, opts); 

    } 

같은 문제에 직면 해있는 친구 ... 감사합니다!