private static BitmapModel BitmapToModel(Bitmap image) { using var stream = new MemoryStream(); image.Save(stream, ImageFormat.Jpeg); var base64String = Convert.ToBase64String(stream.ToArray()); BitmapModel model = new BitmapModel() { Title = "Result", Content = base64String }; return(model); }
public static async Task <IActionResult> RunAsync( [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, ILogger log) { log.LogInformation("C# HTTP trigger function processed a request."); string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); BitmapModel bitmap = JsonConvert.DeserializeObject <BitmapModel>(requestBody); var bytes = Convert.FromBase64String(bitmap.Content); try { var image = new Bitmap(new MemoryStream(bytes)); var modifiedBitmap = await ConvertBitmapToBlackAndWhiteAsync(image); return(new OkObjectResult(BitmapToModel(modifiedBitmap))); } catch (Exception ex) { return(new BadRequestObjectResult(ex.Message)); } }