Android side
Public String uploadheadimg (Bitmap bitmap,string fileName) {
String[] arg={"btyestring", "FileName"};
String[] val={bitmaptostring (bitmap), fileName};
return BD. Getwebreturnmodel ("UploadFile", Arg, Val);
}
Public String bitmaptostring (Bitmap Bitmap) {
Convert Bitmap to String
string string = null;
Bytearrayoutputstream Bstream = new Bytearrayoutputstream ();
Bitmap.compress (Compressformat.png, Bstream);
byte[] bytes = Bstream.tobytearray ();
String = Base64.encode (bytes);
return string;
}
Public Bitmap Stringtobitmap (string string) {
Convert a string to a bitmap type
Bitmap Bitmap = null;
try {
Byte[] Bitmaparray;
Bitmaparray = Base64.decode (string);
Bitmap = Bitmapfactory.decodebytearray (Bitmaparray, 0,
Bitmaparray.length);
} catch (Exception e) {
E.printstacktrace ();
}
return bitmap;
}
Service Rui
#region File Upload
[WebMethod (Description = "File Upload", EnableSession = True)]
public string UploadFile (String btyestring,string FileName)
{
Try
{
String path = Server.MapPath ("/view/upload/headimg");
byte[] bytes = convert.frombase64string (btyestring);
System.IO.MemoryStream ms = new System.IO.MemoryStream (bytes);
System.Drawing.Bitmap B = (System.Drawing.Bitmap) System.Drawing.Image.FromStream (MS);
Picture Save Path
String NewFileName = DateTime.Now.ToString ("YYYYMMDDHHMMSS") + "_" + FileName;
B.save (path + "/" + NewFileName);
return new Jsonmessage {Success = true, Data = "/view/upload/headimg" +newfilename, Message = "Operation Succeeded"}. ToString ();
}