I'm sending an image via Postman
I want to use the image as an Bitmap in my function.
I am trying
public static async Task<HttpResponseMessage> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
ILogger log)
{
log.LogInformation("IsFundusCalled");
string name = req.Query["image"];
var imageData = ReadFully(req.Body);
Bitmap image;
using (var ms = new MemoryStream(imageData))
{
image = new Bitmap(ms);
}
MemoryStream memoryStream = new MemoryStream();
image.Save(memoryStream, ImageFormat.Jpeg);
HttpResponseMessage httpResponseMessage = new HttpResponseMessage();
httpResponseMessage.Content = new ByteArrayContent(memoryStream.ToArray());
httpResponseMessage.Content.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg");
httpResponseMessage.StatusCode = HttpStatusCode.OK;
return httpResponseMessage;
}
//from https://stackoverflow.com/questions/221925/creating-a-byte-array-from-a-stream
public static byte[] ReadFully(Stream input)
{
byte[] buffer = new byte[16 * 1024];
using (MemoryStream ms = new MemoryStream())
{
int read;
while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
{
ms.Write(buffer, 0, read);
}
return ms.ToArray();
}
}
but i am getting the error:
"System.Private.CoreLib: Exception while executing function: IsFundus. ZKWeb.System.Drawing: A null reference or invalid value was found [GDI+ status: InvalidParameter]."
from : image.Save(memoryStream, ImageFormat.Jpeg);