Dim path As String = Server.MapPath(Context.Request.ApplicationPath & "/upload/test.jpg")
Dim img As System.Drawing.Image = System.Drawing.Image.FromFile(path)
img.RotateFlip(RotateFlipType.Rotate90FlipNone)
img.Save(path)
According to your description, you want to make the rotated image smaller rather than larger, right?
If so , you can try this code:
Dim path As String = Server.MapPath("~/Images1/pic4.jpg")
Dim pic As Bitmap = New Bitmap(path)
Dim pic2 As Bitmap = New Bitmap(pic.Width, pic.Height, PixelFormat.Format32bppRgb)
Dim rawFormat = pic.RawFormat
For x As Integer = 0 To pic.Width - 1
For y As Integer = 0 To pic.Height - 1
pic2.SetPixel(x, y, pic.GetPixel(x, y))
Next
Next
pic2.RotateFlip(RotateFlipType.Rotate90FlipNone)
pic2.Save(path , rawFormat)
Member
103 Points
790 Posts
filesize increase after image rotated.
Aug 19, 2019 11:53 AM|kengkit|LINK
hi guys.. the following url is the article i refer to rotate image and save to directgory.
how can i avoid the file size increase? i test with rotate an image and its changed from 900KB to 12.1MB. any idea?
https://asp-net-example.blogspot.com/2012/03/how-to-rotate-image-in-aspnet.html
Contributor
3710 Points
1043 Posts
Re: filesize increase after image rotated.
Aug 20, 2019 08:55 AM|Yongqing Yu|LINK
Hi kengkit,
According to your description, you want to make the rotated image smaller rather than larger, right?
If so , you can try this code:
Dim path As String = Server.MapPath("~/Images1/pic4.jpg") Dim pic As Bitmap = New Bitmap(path) Dim pic2 As Bitmap = New Bitmap(pic.Width, pic.Height, PixelFormat.Format32bppRgb) Dim rawFormat = pic.RawFormat For x As Integer = 0 To pic.Width - 1 For y As Integer = 0 To pic.Height - 1 pic2.SetPixel(x, y, pic.GetPixel(x, y)) Next Next pic2.RotateFlip(RotateFlipType.Rotate90FlipNone) pic2.Save(path , rawFormat)
You can refer to this link: https://stackoverflow.com/a/33188884
If you want change the size ,you can change PixelFormat.Format32bppRgb to others, you can refer to this link: PixelFormat Enum
Best Regards,
YongQing.
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.