我对发送和获取图像的编码数据有疑问。首先,我将图像作为字符串中的 Base64 编码类型,该字符串具有如下值: ...D/2wBDAA0JCgsKCA0LCgsODg0PEyAVExISEyccHhcgLikxMC4pLSwzOko+MzZ ...
现在,如果我再次解码并且如果我使用 BitmapFactory 来适应 imageview 那就没问题了,图像就可以了。
byte[] bytes= stream.toByteArray();
imagestr=Base64.encodeBytes(bytes).toString();
//If i code below it is working
byte[] decode = Base64.decode(imagestr);
decoded = BitmapFactory.decodeByteArray(decode, 0, decode.length);
//If i send to the server and handle it in servlet file
String pic = request.getParameter("p");
byte[] servdec = Base64.decode(pic);
//and if i use the servdec to output a image file file is corrupted.
//I noticed the pic and imagestr are different
//imagestr = **...D/2wBDAA0JCgsKCA0LCgsODg0PEyAVExISEyccHhcgLikxMC4pLSwzOko+MzZ...**
//pic = **...D/2wBDAA0JCgsKCA0LCgsODg0PEyAVExISEyccHhcgLikxMC4pLSwzOko MzZ...**
//pic has no + sign.
我使用了replaceAll,但这仅适用于这种情况。它可能会导致更多的问题。所以有什么解决办法吗,谢谢你的回答。。。
嗨,这个字符串在这个函数的 pic 中,这个函数 servlet 将处理这个!pic 在这个函数中有 + 符号
public String uuidfaceid(String uuid,String faceid, String name,String pic){
URL url = null;
try {
url = new
URL("http://"+Constants.SERVER_NAME+Constants.SERVER_PORT+"/MeetInTouch/UF"+"?uuid="+uuid+"&faceid="+faceid+"&name="+name+"&pic="+pic);
} catch (MalformedURLException e1) {
e1.printStackTrace();
}
URLConnection ucon = null;
try {
ucon = url.openConnection();
} catch (IOException e1) {
e1.printStackTrace();
}
try {
ucon.connect();
} catch (IOException e1) {
e1.printStackTrace();
}