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")
System.IO.File.WriteAllBytes(filePath, bytes)
This document explains how to compress and decompress files using classes under System.IO.Com compression namespace.
Best regards,
Sam
MSDN Community Support
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.
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
size).
Member
90 Points
726 Posts
reduce file size in base64String
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") System.IO.File.WriteAllBytes(filePath, bytes)
Participant
1870 Points
712 Posts
Re: reduce file size in base64String
Aug 19, 2019 11:42 AM|samwu|LINK
Hi kengkit,
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.
Best regards,
Sam
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.
All-Star
45840 Points
16682 Posts
Re: reduce file size in base64String
Aug 21, 2019 12:47 PM|PatriceSc|LINK
Hi,
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 size).