Nativescript IOS: Compress Photo in Nativescript and Decompress in C# API

20 views Asked by At

I am reducing the quality of the photo , which reduces the size of the photo on the nativescript ios app.

I am doing this to send the smaller files to the server on upload and process it on the server side in C# to prevent timeouts and performance issues.

Here i am reducing the quality and size of the photos in Nativescript/Angular/IOS:

const imagePath = "path/to/your/image.jpg";

// Convert the image to a compressed format (e.g., JPEG) with a desired quality
const compressedBase64StringImage = ImageSource.fromFileSync(imagePath).toBase64String("jpeg",5);

The Decompress code which i have does not seem to increase the size or quality of the photo

  static byte[] DecompressImage(byte[] compressedData)
    {
        using (MemoryStream compressedStream = new MemoryStream(compressedData))
        using (MemoryStream decompressedStream = new MemoryStream())
        {
            using (var image = Image.FromStream(compressedStream))
            {
                image.Save(decompressedStream, ImageFormat.Jpeg);
            }

            return decompressedStream.ToArray();
        }
    }

how can i restore the size and quality of the photo on the server side c#. Please Help.

0

There are 0 answers