I'm sending image from Android to C# webservice. I always get a black image.Can anyone help?
Android side:
public void save(View v) {
mBitmap = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.RGB_565);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
mBitmap.compress(Bitmap.CompressFormat.JPEG,40, outputStream);
byte[] imgByte = outputStream.toByteArray();
String base64Str = Base64.encodeToString(imgByte, Base64.DEFAULT);
// Send base64Str to server
}
C# side:
[WebMethod]
public void GetImage(string base64ImageStr)
{
byte[] imageBytes = Convert.FromBase64String(base64ImageStr);
//Save imageBytes to DB
}
I'm calling it from DB:
public ActionResult Image(){
var bytes=GetBytesArrayFromDB(id);
return File(bytes, "image/jpeg");
}
in View:
<img src='@Url.Action("Image")' alt="" />
I figure it out I didn't Canvas it before sending it to server. use this too
Canvas canvas = new Canvas(mBitmap); v.draw(canvas);
//send base64Str to server
}