- Aurigma Graphics Mill 5.5 for .NET
- Introduction
- What's New?
- Overview of Features
- Getting Started
- Programming with Graphics Mill for .NET
- File Formats
- Graphics Mill for .NET Add-ons
- Class Library Reference
- Aurigma.GraphicsMill Namespace
- Aurigma.GraphicsMill.AjaxControls Namespace
- Aurigma.GraphicsMill.AjaxControls.VectorObjects Namespace
- Aurigma.GraphicsMill.AjaxControls.VectorObjects.Math Namespace
- Aurigma.GraphicsMill.AjaxControls.VectorObjects.RedoUndo Namespace
- Aurigma.GraphicsMill.Codecs Namespace
- AdobeResourceBlock Class
- AdobeResourceDictionary Class
- AdvancedPsdFrame Class
- AdvancedPsdReader Class
- AdvancedPsdTextFrame Class
- AsfIndexer Class
- AviAlphaTransition Class
- AviAudioManager Class
- AviCompressor Class
- AviCustomTransition Class
- AviDrawTransitionEventArgs Class
- AviDrawTransitionEventHandler Delegate
- AviDrawWatermarkEventArgs Class
- AviDrawWatermarkEventHandler Delegate
- AviEncoderOptions Class
- AviFrame Class
- AviReader Class
- AviStripesTransition Class
- AviStripesTransitionMode Enumeration
- AviTimerStyle Enumeration
- AviTransition Class
- AviWatermark Class
- AviWriter Class
- BmpEncoderOptions Class
- BmpFrame Class
- BmpReader Class
- BmpWriter Class
- CompressionType Enumeration
- CustomEncoderOptions Class
- CustomFormatReader Class
- CustomFormatReader.LoadingMode Enumeration
- CustomFormatWriter Class
- CustomFrame Class
- DisposalMethod Enumeration
- DSEncoderOptions Class
- DSFrame Class
- DSPreLoadedFrame Class
- DSReader Class
- EncoderOptions Class
- ExifDictionary Class
- ExifItemInfo Structure
- FormatManager Class
- FormatReader Class
- FormatWriter Class
- Frame Class
- GifEncoderOptions Class
- GifFrame Class
- GifReader Class
- GifWriter Class
- ID3LyricsContentType Enumeration
- ID3LyricsTimestampFormat Enumeration
- ID3SynchronisedLyrics Class
- IEncoderOptions Interface
- IFormatInfo Interface
- IFormatReader Interface
- IFormatWriter Interface
- IFrame Interface
- IFrameEnumerator Interface
- IMediaProcessorMetadataReadSupport Interface
- IMetadataReadSupport Interface
- IMetadataWriteSupport Interface
- IptcDictionary Class
- ITimeReader Interface
- ITimeWriter Interface
- IXmpDictionary Interface
- Jpeg2kEncoderOptions Class
- Jpeg2kFrame Class
- Jpeg2kProgressionOrder Enumeration
- Jpeg2kReader Class
- Jpeg2kWriter Class
- JpegAlignToSampleSizeMode Enumeration
- JpegEncoderOptions Class
- JpegFrame Class
- JpegMarkerException Class
- JpegReader Class
- JpegWriter Class
- LosslessJpegTransform Class
- MediaCorruptedException Class
- MediaFormatManager Class
- MediaProcessorMetadataDictionary Class
- MediaProviderException Class
- MediaUnsupportedException Class
- MetadataDictionary Class
- MetadataEnumerator Class
- MultiFrameException Class
- PcxEncoderOptions Class
- PcxFrame Class
- PcxReader Class
- PdfEncoderOptions Class
- PdfFrame Class
- PdfWriter Class
- PngEncoderOptions Class
- PngFrame Class
- PngReader Class
- PngWriter Class
- PreLoadedFrame Class
- PsdEncoderOptions Class
- PsdFrame Class
- PsdFrameType Enumeration
- PsdReader Class
- PsdTextJustification Enumeration
- QTEncoderOptions Class
- QTFrame Class
- QTReader Class
- SwfEncoderOptions Class
- SwfFrame Class
- SwfWriter Class
- TiffChannelType Enumeration
- TiffEncoderOptions Class
- TiffExtraChannel Class
- TiffExtraChannelCollection Class
- TiffFrame Class
- TiffReader Class
- TiffWriter Class
- WbmpEncoderOptions Class
- WbmpFrame Class
- WbmpReader Class
- WbmpWriter Class
- WMEncoderOptions Class
- WMFrame Class
- WMPreLoadedFrame Class
- WMReader Class
- XmpArrayNode Class
- XmpData Class
- XmpDictionaryNode Class
- XmpLocalizedTextItemNode Class
- XmpLocalizedTextNode Class
- XmpNamespace Class
- XmpNode Class
- XmpNodeType Enumeration
- XmpStructNode Class
- XmpTagNames Class
- XmpValueNode Class
- Aurigma.GraphicsMill.Drawing Namespace
- Aurigma.GraphicsMill.Licensing Namespace
- Aurigma.GraphicsMill.Transforms Namespace
- Aurigma.GraphicsMill.WebControls Namespace
- Aurigma.GraphicsMill.WinControls Namespace
- GraphicsMill Namespace (Client Class Library)
- Aurigma.GraphicsMill.AjaxControls Namespace (Client Class Library)
- Aurigma.GraphicsMill.AjaxControls.VectorObjects Namespace (Client Class Library)
- Aurigma.GraphicsMill.AjaxControls.VectorObjects.Math Namespace (Client Class Library)
- Aurigma.GraphicsMill.AjaxControls.VectorObjects.RedoUndo Namespace (Client Class Library)
- Samples
- Licensing
- Copyright Notices
LosslessJpegTransform.WriteCropped Method (String, Rectangle)
Crops a portion of the uncompressed JPEG image and writes it to specified file.
Namespace:
Aurigma.GraphicsMill.Codecs
Assembly:
Aurigma.GraphicsMill (in Aurigma.GraphicsMill.dll)
Syntax
Parameters
- fileName
-
Type: System.String
The name of the file where you want to save the result.
- rectangle
-
Type: System.Drawing.Rectangle
Rectangle object which specifies a portion of the image you need to crop. The rectangle must be inside the image. Note, coordinates of this rectangle and coordinates of the cropped portion of image may be different (see Remarks section for more details).
Remarks
You can use this method to recompress only a part of an image. For example, let's assume you want to apply a watermark to an image or remove an effect of red eyes. It obviously makes sense to recompress only that part of image which you modify without recompressing the other parts. It can be easily achieved with the following algorithm:
- Determine what part of image you need to change. You may need to load it into a bitmap so that the user could select this part manually, or calculate it somehow else.
- Create LosslessJpegTransform and open it using the Open(String) method.
- Use AlignToSampleSize(Point, Bitmap) to align the rectangle specifying the image part to JPEG sample size (see below).
- Use the WriteCropped(Stream, Rectangle) to get a portion of JPEG without recompression.
- Create a new Bitmap instance and load the resulting JPEG file into it (e.g. using the Load(String) method).
- Apply the necessary effect to the bitmap (e.g. watermark, red eye removal, etc).
- Use the WritePatched(String, Point, Bitmap) method to store the resulting bitmap into a JPEG file. Graphics Mill for .NET will automatically compress this bitmap with the same compression options as the original JPEG file and overwrite the appropriate portion of compressed JPEG data.
- Do not forget to close the LosslessJpegTransform with the Close() method.
Due to specifics of JPEG, you cannot specify arbitrary coordinates to crop. Its top-left corner should be aligned on the size of JPEG sample data. Typically it is a number divisible by 8. To calculate the actual rectangle, you can use the AlignToSampleSize(Rectangle, JpegAlignToSampleSizeMode) method. You just pass your rectangle to this method and it returns the nearest rectangle (with modified position aligned to the JPEG sample size).
If you pass a rectangle which is not aligned, Graphics Mill for .NET automatically aligns it. As a result, coordinates of the left-top corner of this rectangle will be rounded down by the JPEG sample size but coordinates of the right-bottom corner will not be changed. For example, if you specify this rectangle (11, 11, 20, 20) it will be aligned to (8, 8, 23, 23) if the JPEG sample size is 8x8.
See Also
Reference
- LosslessJpegTransform Class
- WriteCropped Overload
- Aurigma.GraphicsMill.Codecs Namespace
- LosslessJpegTransform.AlignToSampleSize(Rectangle, JpegAlignToSampleSizeMode)
- LosslessJpegTransform.Write(String)
- LosslessJpegTransform.WritePatched(String, Point, Bitmap)
- LosslessJpegTransform.WriteRotated(String, RotateFlipType)
- LosslessJpegTransform.WriteTransposed(String)
- LosslessJpegTransform.WriteTransversed(String)