私はアンドロイドで同じ問題に直面しました、正確な問題は何ですか_画像を対応するものにエンコードするときBase64
&画像サイズがもっと大きい場合(2mb以上...&画質とカメラ品質にも依存します、2MPから取得される可能性がありますまたは5MPまたは8MPカメラの場合もあります)その後、完全な画像をBase64に変換する際に問題が発生します...問題の画像のサイズを小さくする必要があります!私はそれを達成した私の仕事Android code
を与えました_GetBase64image
String
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);
適切なビットマップに変換する
/**
*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);
}
これが同じ問題に直面している他の仲間に役立つことを願っています...ありがとう!