在URL中附加编码的base64字符串值时,我得到NULL值。
public void onActivityResult ( int requestCode, int resultCode, Intent data){
if (requestCode == CAMERA_REQUEST && resultCode == Activity.RESULT_OK) {
Uri imageUri = data.getData();
imageView.setImageURI(imageUri);
imageView.buildDrawingCache();
Bitmap bmap = imageView.getDrawingCache();
bitmapToBase64(bmap);
} else if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK ) {
Uri imageUri = data.getData();
imageView.setImageURI(imageUri);
imageView.buildDrawingCache();
Bitmap bmap = imageView.getDrawingCache();
bitmapToBase64(bmap);
//Bitmap image = (Bitmap) data.getExtras().get("data");
}
}
public String bitmapToBase64(Bitmap bitmap) {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 70, byteArrayOutputStream);
byte[] byteArray = byteArrayOutputStream.toByteArray();
String encoderes = Base64.encodeToString(byteArray, Base64.DEFAULT);
encodestr.setText(encoderes);
return encoderes;
}
上面的代码是将图像编码为base64字符串但在附加到URL时,字符串变量encoderes显示为null
url="http://10.0.2.2/newz/newz/Mobile_api/photo_decode?photo_encode="+encoderes";