---
title: "Resize while reading JPEG"
canonical: https://www.graphicsmill.com/samples/Codecs/Jpeg/ResizeWhileReadingJpeg_cs
product: "Graphics Mill"
source: "Codecs/Jpeg/ResizeWhileReadingJpeg.cs"
---

# Resize while reading JPEG

Demonstrates how to resize a JPEG image using the codec's resize capability.

## Instruction

Write a C# program that resizes a JPEG image by a factor of 2 during decoding using `JpegReader.Scale`, and saves the result to a new image.

## Usings

```csharp
using Aurigma.GraphicsMill.Codecs;
```

## Code Snippet

```csharp
using (var reader = new JpegReader("Chicago.jpg"))
{
    reader.Scale = JpegScale.x2;

    using (var bitmap = reader.Frames[0].GetBitmap())
    {
        bitmap.Save("ResizeWhileReadingJpeg.jpg");
    }
}
```

## Explanation

Here is a C# program that performs JPEG decoding with downscaling by a factor of 2 using the `JpegReader.Scale` property:

This approach uses the JPEG format’s ability to scale down while decoding, improving performance for resizing operations.

## Tags

- [Filesystem](<https://www.graphicsmill.com/samples/tags/filesystem_md>): Loading and saving images from files
- [JPG](<https://www.graphicsmill.com/samples/tags/jpg_md>): Reading and writing JPEG images
- [Read](<https://www.graphicsmill.com/samples/tags/read_md>): Reading images with codecs
- [Resize](<https://www.graphicsmill.com/samples/tags/resize_md>): Resizing images
- [Write](<https://www.graphicsmill.com/samples/tags/write_md>): Writing images with codecs

## Input

- [Chicago.jpg](<https://www.graphicsmill.com/samples/Codecs/compiled/Debug/Chicago_jpg>) (preview)

## Output

- [ResizeWhileReadingJpeg.jpg](<https://www.graphicsmill.com/samples/Codecs/compiled/Debug/ResizeWhileReadingJpeg_jpg>) (preview)

## Used APIs

- [Aurigma.GraphicsMill.Codecs.Frame.GetBitmap](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Codecs_Frame_GetBitmap.htm.md>)
- [Aurigma.GraphicsMill.Codecs.ImageReader.Frames](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_ImageReader_Frames.htm.md>)
- [Aurigma.GraphicsMill.Codecs.JpegReader](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Codecs_JpegReader.htm.md>)
- [Aurigma.GraphicsMill.Codecs.JpegReader.Scale](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Codecs_JpegReader_Scale.htm.md>)
- [Aurigma.GraphicsMill.Codecs.JpegScale](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Codecs_JpegScale.htm.md>)
