1

画像のエンコードされたデータの送信と取得について質問があります。まず、文字列に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 にあります。この関数サーブレットがこれを処理した後、!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();

}
4

1 に答える 1

0

Base64でエンコードされた文字列を含む「p」が、ある時点で「URLデコード」されたパラメータ。Base64をデコードする前に、もう一度エンコードするだけです。

String pic = request.getParameter("p");
pic = URLEncoder.encode(pic, "ISO-8859-1");
byte[] servdec = Base64.decode(pic);
于 2013-03-16T19:23:26.787 に答える