Guest User

Untitled

a guest
Nov 16th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. public void Post(FlyerDetails FlyerDetails)
  2. {
  3. var httpRequest = HttpContext.Current.Request;
  4. if (httpRequest.Files.Count > 0)
  5. {
  6. foreach (string file in httpRequest.Files)
  7. {
  8. var filePath = HttpContext.Current.Server.MapPath("~/Flyers/" + httpRequest.Files[file].FileName);
  9. Bitmap bmp = new Bitmap(httpRequest.Files[file].InputStream);
  10. Graphics g = Graphics.FromImage(bmp);
  11. g.SmoothingMode = SmoothingMode.AntiAlias;
  12. g.InterpolationMode = InterpolationMode.HighQualityBicubic;
  13. g.PixelOffsetMode = PixelOffsetMode.HighQuality;
  14. g.DrawString(FlyerDetails.Message, new Font(FlyerDetails.FontColor, FlyerDetails.FontSize), Brushes.DarkRed, new PointF(0, 0));
  15. g.Flush();
  16. bmp.Save(filePath);
  17. }
  18. }
  19. }
  20.  
  21. public async Task<HttpResponseMessage> Post()
  22. {
  23.  
  24. var streamProvider = new MultipartFormDataStreamProvider(HttpContext.Current.Server.MapPath("~/Flyers/"));
  25. await Request.Content.ReadAsMultipartAsync(streamProvider);
  26.  
  27. var response = Request.CreateResponse(HttpStatusCode.Created);
  28. var filePath = "";// file path
  29. if (System.IO.File.Exists(filePath))
  30. {
  31. string extension = Path.GetExtension(filePath);
  32. Bitmap bmp = new Bitmap(filePath);
  33. Graphics g = Graphics.FromImage(bmp);
  34. g.SmoothingMode = SmoothingMode.AntiAlias;
  35. g.InterpolationMode = InterpolationMode.HighQualityBicubic;
  36. g.PixelOffsetMode = PixelOffsetMode.HighQuality;
  37. Color brushColor = System.Drawing.ColorTranslator.FromHtml(streamProvider.FormData["FontColorCode"]);
  38. g.DrawString(streamProvider.FormData["FontFamily"], new Font(brushColor.Name, Convert.ToInt32(streamProvider.FormData["FontSize"])), new SolidBrush(brushColor), new PointF(0, 0));
  39. g.Flush();
  40. bmp.Save(HttpContext.Current.Server.MapPath("~/" + Guid.NewGuid() + extension));
  41. response.Headers.Location = new Uri(new Uri(HttpContext.Current.Request.Url.AbsoluteUri).GetLeftPart(UriPartial.Authority) + "/Flyers/" + Guid.NewGuid() + extension);
  42. }
  43. return response;
  44. }
  45.  
  46. string value = HttpContext.Current.Request.Params.Get("key");
Add Comment
Please, Sign In to add comment