Guest User

Untitled

a guest
May 26th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. public FileResult Icons4(float angle)
  2. {
  3. try
  4. {
  5. //It changes according to the conditions of this route
  6. string path = "myPath";
  7. Bitmap orgbmp = (Bitmap)Image.FromFile(path);
  8.  
  9. Bitmap bmp = CropTranslate(orgbmp);
  10.  
  11. Bitmap tempRotatedImage = new Bitmap((bmp.Width * 2) + 10, (bmp.Height * 2) + 10, PixelFormat.Format32bppArgb);
  12. using (Graphics g = Graphics.FromImage(tempRotatedImage))
  13. {
  14. g.Clear(Color.Transparent);
  15. g.DrawImage(bmp, new Point(((int)(bmp.Width / 2) + 3), ((int)(bmp.Height / 2)) + 3));
  16. }
  17.  
  18. Bitmap rotatedImage = new Bitmap(tempRotatedImage.Width, tempRotatedImage.Height);
  19. using (Graphics g = Graphics.FromImage(rotatedImage))
  20. {
  21. g.TranslateTransform(tempRotatedImage.Width / 2, tempRotatedImage.Height / 2);
  22. g.RotateTransform(angle);
  23. g.TranslateTransform(-tempRotatedImage.Width / 2, -tempRotatedImage.Height / 2);
  24. g.DrawImage(tempRotatedImage, new Point(0, 0));
  25. }
  26.  
  27. Bitmap croped = CropTranslate(rotatedImage);
  28. double wid = rotatedImage.Width;
  29. double hig = rotatedImage.Height;
  30. if (wid > 64 || hig > 64)
  31. {
  32.  
  33. if (croped.Width > croped.Height)
  34. {
  35. wid = 64;
  36. hig = (int)(64 / wid) * 64;
  37. }
  38. else
  39. {
  40. wid = (int)((64 / hig) * 64);
  41. hig = 64;
  42. }
  43. }
  44.  
  45. Size newSize = new Size((int)wid , (int)hig );
  46. Bitmap newBmp = new Bitmap(croped, newSize);
  47.  
  48. ImageConverter converter = new ImageConverter();
  49. var bytes = (byte[])converter.ConvertTo(newBmp, typeof(byte[]));
  50. return File(bytes, System.Net.Mime.MediaTypeNames.Application.Octet, "test.png");
  51.  
  52. }
  53. catch (Exception x)
  54. {
  55. WriteLog("cntrlr" + GetException(x));
  56. }
  57. return null;
  58. }
Add Comment
Please, Sign In to add comment