我正在尝试在MSSQL服务器中以字符串格式存储从摄像头(android)拍摄的Base64编码的全尺寸图像。援引的
Save the full-size photo
代码生成的编码字符串给出了正确的字符串,但当我在MSSQL服务器中保存相同的字符串时,它是编码字符串的一半。尝试使用VARCHAR(MAX)和NVARCHAR(MAX)存储字符串,但问题相同。
这是我的密码。
//Method to encode bitmap
public static String encodeTobase64(Bitmap image) {
Bitmap immagex=image;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
immagex.compress(Bitmap.CompressFormat.PNG, 100, baos);
byte[] b = baos.toByteArray();
String imageEncoded = Base64.encodeToString(b,Base64.DEFAULT);
return imageEncoded;
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
SendImageString="";
if (mCurrentPhotoPath!=null){
File image = new File(mCurrentPhotoPath);
try {
Bitmap myBitmap = new
Compressor(this).compressToBitmap(image);
Bitmap resized = Bitmap.createScaledBitmap(myBitmap,
800, 600, true);
img_takenpisture.setImageBitmap(resized);
SendImageString = encodeTobase64(resized);
IsImageClick=true;
} catch (Exception e) {
e.printStackTrace();
}
}
}
}