Select language
  1. Products
  2. Aspose.Imaging
  3. Image compress
clearbit icon

Compress image for .NET

Buy for $99
Share
Instagram Logo Dribbble Logo Twitter Logo Youtube Logo

How to compress images Using .NET Library

In order to compress images, we’ll use Aspose.Imaging for .NET API which is a feature-rich, powerful and easy to use image manipulation API for net platform. Open NuGet package manager, search for Aspose.Imaging and install. You may also use the following command from the Package Manager Console.

1
Install-Package Aspose.Imaging

Compress images via .NET

You need Aspose.Imaging Compress for .NET metered license to try the code in your environment.

  1. Load the Image with an instance of specific Image class.
  2. Create image options to compress the image
  3. Save or export image in the desired image format, defined by the options

System Requirements

Just make sure that you have the following prerequisites.

  • Microsoft Windows or a compatible OS with .NET Core
  • Development environment like Visual Studio Code or Microsoft Visual Studio.
  • Aspose.Imaging for .NET DLL referenced in your project.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using System;
 using Aspose.Imaging;

namespace CSharpTutorials
{
    class Program
    {
        static void Main(string[] args)
        {
            Metered metered = new Metered();
            metered.SetLicense("***********", // public key
                               "***********"  // private key
                              );

            // This code compresses png             
            using (var image = Image.Load("tiger.png"))
            {
                image.Save("tiger_compressed.png", new PngOptions
                {
                    CompressionLevel = 9,
                    Progressive = true,
                    ColorType = PngColorType.IndexedColor,
                    Palette = ColorPaletteHelper.GetCloseImagePalette((RasterImage)image, 1 << 5)
                });
            }
        }
    }
}

You may find other allowed compress cases and examples here