ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,741 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I want to Compress all uploaded image before it gets Uploaded on the websites disk.
I have allot of small thumbnail sized images (shopping page) on a page so the images need to be at there minimal size while stil be in good quality so it will not take that long to load a page
How I upload the images right now:
string name = Guid.NewGuid().ToString() + "_" + image.FileName;
string filepath = Path.Combine(root, name);
using var stream = System.IO.File.Create(filepath);
await image.CopyToAsync(stream);
You can do something like the below,
Bitmap resizedImage = new(image, new Size(256, 256));
using var stream = new MemoryStream();
resizedImage.Save(stream, ImageFormat.Jpeg);
byte[] bytes = stream.ToArray();
// Write bytes to your desired location