Last post Aug 21, 2019 12:47 PM by PatriceSc
Aug 19, 2019 04:14 AM|kengkit|LINK
Hi guys.. i found that the filesize changed from 993KB to 9.1MB after rotated the image and save it.
Like to know is there any method to reduce file-size during this stage?
Below is my coding, hfData is data of the rotated image.
Dim base64String As String = hfData.Value.Replace("data:image/png;base64,", String.Empty)
Dim bytes As Byte() = Convert.FromBase64String(base64String)
Dim filePath As String = Server.MapPath(Context.Request.ApplicationPath & "/upload/newfile.jpg")
Aug 19, 2019 11:42 AM|samwu|LINK
You can try compress the image first and save the image using base64string.
About how to Compress and extract files you can refer to this link: https://docs.microsoft.com/en-us/dotnet/standard/io/how-to-compress-and-extract-files
This document explains how to compress and decompress files using classes under System.IO.Com compression namespace.
Aug 21, 2019 12:47 PM|PatriceSc|LINK
base64 is just a way to encode binary content with "printable ASCII characters", and once decoded you just get the same binary content.
More likely your rotation code is changing something else such as the image width/height, the file format (seems you are unsure if this is a png or jpg ?) and/or the compression level. This is done client side with a canvas before an upload ?
Double check your rotation code. I would try maybe to rotate the same image with System.Drawing.Bitmap (not to solve the issue, but just to make sure the size you can expect for the properly rotated image which I expect to, be much closer to the original