主要针对服务器端和客户端利用BASE64对图片和字符串进行编码解码操作。
客户端是Android,服务器端是webservice,编码解码方式如下:
一、Android 实现图片上传
1.java对图片进行编码
Bitmap image = extras.getParcelable("data");
if (image != null) {
try {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
image.compress(Bitmap.CompressFormat.JPEG, 60,stream);
byte[] b = stream.toByteArray(); // 将图片流以字符串形式存储下来
tp = new String(Base64Coder.encodeLines(b));//转换后的字符串,可将该字符串上传至服务器端进行解码
myIndustryImg.setImageBitmap(image);// 把图片显示到头像
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
2.C#(webservice端)接收字符串,进行解码。
[WebMethod(Description = "上传图片")]
public bool uploadImage(string filename, string imageString)
{
ConnCls myconncls = new ConnCls();
st