我需要发送的图像(从画廊)到服务器的base64字符串的格式。我获取了图像的路径,并将其转换为base64字符串。但是在服务器上,图像并没有完全显示出来。只有10%的图像显示在服务器side.Please谁能帮我把图像转换成base64字符串。
代码:
filePath = cursor.getString(columnIndex);
Bitmap bitmapOrg = BitmapFactory.decodeFile(filePath);
ByteArrayOutputStream bao = new ByteArrayOutputStream();
bitmapOrg.compress(CompressFormat.PNG, 100, bao);
byte [] ba = bao.toByteArray();
ba1 =Base64.encodeToString(ba, Base64.DEFAULT);
图片大小:460kb
发布于 2015-05-02 17:09:39
尝试这个,我希望它会为你工作,并使用httpPost方法发送。
公共静态字符串BitmapToString(位图bmp) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
String base64 = Base64.encodeToString(byteArray, Base64.DEFAULT);
return base64;
}
( Base64 base64=new Base64);
Base64(saveImage(ProfilePic),"yourName");
public void saveImage(byte[] bytes,String name){
String path="D:/"+name.hashCode()+".png";
try {
FileOutputStream f = new FileOutputStream(path);
f.write(bytes);
f.close();
} catch (Exception e) {
e.printStackTrace();
}
}
https://stackoverflow.com/questions/30000397
复制相似问题