Last post Aug 20, 2019 08:55 AM by Yongqing Yu
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?
Dim path As String = Server.MapPath(Context.Request.ApplicationPath & "/upload/test.jpg")
Dim img As System.Drawing.Image = System.Drawing.Image.FromFile(path)
Aug 20, 2019 08:55 AM|Yongqing Yu|LINK
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))
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