How to compress an base 64 image before saving it c#

57 Views Asked by At

I'm trying to create an converter that converts a base64 string to a saved image. Now I'm trying to compress the image before saving it. Is there any way to "compress" the array of bytes before I save it? I want the image to take less space on my drive (2mb to <1mb).

Example:

byte[] bytes = Convert.FromBase64String(base64string);

// change the file size


// Save the image
await using FileStream fs = new(filePath, FileMode.Create);
using var ms = new MemoryStream(bytes);
await ms.CopyToAsync(fs);

I searched on the internet for some solutions but could not find any.

0

There are 0 best solutions below