---
title: "LosslessJpeg.AlignToMCUSize Method (Rectangle, JpegAlignToSampleSizeMode)"
canonical: https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Codecs_LosslessJpeg_AlignToMCUSize_2_196b06b9.htm
product: "Graphics Mill"
---

# LosslessJpeg.AlignToMCUSize Method (Rectangle, JpegAlignToSampleSizeMode)
 
Aligns the rectangle to JPEG Minimum Coded Units (MCU).
 
**Namespace:** [Aurigma.GraphicsMill.Codecs](https://www.graphicsmill.com/docs/gm/N_Aurigma_GraphicsMill_Codecs.htm.md)
 **Assembly:** Aurigma.GraphicsMill (in Aurigma.GraphicsMill.dll)
 
## Syntax
  
```csharp
public Rectangle AlignToMCUSize(Rectangle rectangle,JpegAlignToSampleSizeMode mode
)
```
 
### Parameters
 
 - rectangle
     - Type: System.Drawing.Rectangle
A Rectangle to align to MCU.

 - mode
     - Type: [Aurigma.GraphicsMill.Codecs.JpegAlignToSampleSizeMode](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Codecs_JpegAlignToSampleSizeMode.htm.md)
A [JpegAlignToSampleSizeMode](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Codecs_JpegAlignToSampleSizeMode.htm.md) specifying whether to align only coordinates of the upper-left corner, or width and height also. See the **Remerks** section for details.
 
### Return Value
A Rectangle aligned to MCU. It is always greater or equal than the input *rectangle*.
 
## Remarks
  
This method is used when you need overwrite some portion of JPEG image by some bitmap. Since JPEG compressed data is stored in blocks (samples) of several pixels (typically 8, 16, or other number divisible by 8), you cannot write bitmap by arbitrary coordinates. That's why you need to align coordinates by JPEG Minimum Coded Units (MCU).
 
If you need just to crop an image and you do not want to use it as patch for another image, you can use the [Crop](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Codecs_JpegAlignToSampleSizeMode.htm.md) value. In this case the width and height of the cropping rectangle can be arbitrary.
 
However if you are going to put this image onto another (i.e. patch it), the width and height of this image must be aligned. In this case you should use [Patch](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Codecs_JpegAlignToSampleSizeMode.htm.md) value.
   
## See Also

### Reference

- [LosslessJpeg Class](https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Codecs_LosslessJpeg.htm.md)
- [AlignToMCUSize Overload](https://www.graphicsmill.com/docs/gm/O_T_Aurigma_GraphicsMill_Codecs_LosslessJpeg_AlignToMCUSize.htm.md)
- [Aurigma.GraphicsMill.Codecs Namespace](https://www.graphicsmill.com/docs/gm/N_Aurigma_GraphicsMill_Codecs.htm.md)
- [LosslessJpeg.WriteCropped()](https://www.graphicsmill.com/docs/gm/O_T_Aurigma_GraphicsMill_Codecs_LosslessJpeg_WriteCropped.htm.md)
- [LosslessJpeg.WritePatched()](https://www.graphicsmill.com/docs/gm/O_T_Aurigma_GraphicsMill_Codecs_LosslessJpeg_WritePatched.htm.md)
