Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public FileResult Icons4(float angle)
- {
- try
- {
- //It changes according to the conditions of this route
- string path = "myPath";
- Bitmap orgbmp = (Bitmap)Image.FromFile(path);
- Bitmap bmp = CropTranslate(orgbmp);
- Bitmap tempRotatedImage = new Bitmap((bmp.Width * 2) + 10, (bmp.Height * 2) + 10, PixelFormat.Format32bppArgb);
- using (Graphics g = Graphics.FromImage(tempRotatedImage))
- {
- g.Clear(Color.Transparent);
- g.DrawImage(bmp, new Point(((int)(bmp.Width / 2) + 3), ((int)(bmp.Height / 2)) + 3));
- }
- Bitmap rotatedImage = new Bitmap(tempRotatedImage.Width, tempRotatedImage.Height);
- using (Graphics g = Graphics.FromImage(rotatedImage))
- {
- g.TranslateTransform(tempRotatedImage.Width / 2, tempRotatedImage.Height / 2);
- g.RotateTransform(angle);
- g.TranslateTransform(-tempRotatedImage.Width / 2, -tempRotatedImage.Height / 2);
- g.DrawImage(tempRotatedImage, new Point(0, 0));
- }
- Bitmap croped = CropTranslate(rotatedImage);
- double wid = rotatedImage.Width;
- double hig = rotatedImage.Height;
- if (wid > 64 || hig > 64)
- {
- if (croped.Width > croped.Height)
- {
- wid = 64;
- hig = (int)(64 / wid) * 64;
- }
- else
- {
- wid = (int)((64 / hig) * 64);
- hig = 64;
- }
- }
- Size newSize = new Size((int)wid , (int)hig );
- Bitmap newBmp = new Bitmap(croped, newSize);
- ImageConverter converter = new ImageConverter();
- var bytes = (byte[])converter.ConvertTo(newBmp, typeof(byte[]));
- return File(bytes, System.Net.Mime.MediaTypeNames.Application.Octet, "test.png");
- }
- catch (Exception x)
- {
- WriteLog("cntrlr" + GetException(x));
- }
- return null;
- }
Add Comment
Please, Sign In to add comment