Compresses given bitmap to JPEG, overwrites a portion of JPEG data of the LosslessJpegTransform by this bitmap, and writes the result into the specified stream.
Namespace:
Aurigma.GraphicsMill.Codecs
Assembly:
Aurigma.GraphicsMill (in Aurigma.GraphicsMill.dll)
Public Sub WritePatched ( _ stream As Stream, _ offset As Point, _ bitmap As Bitmap _ )
Type: System.IO.Stream
The stream where you want to save the result.Type: System.Drawing.Point
Point at which the bitmap should be placed. These coordinates must be inside of image (i.e. x-coordinate must be smaller than width, y-coordinate must be smaller than height). Note, it should be aligned on the JPEG data sample size (see the Remarks section for more details).Type: Aurigma.GraphicsMill.Bitmap
An instance of the Bitmap class which should be placed at the given position.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:
Due to specifics of JPEG, you cannot put the bitmap at arbitrary coordinates. They should be aligned on the size of JPEG sample data. Typically it is a number divisible by 8. To calculate aligned coordinates, you can use the AlignToSampleSize(Point, Bitmap) method. You just pass your position and the bitmap to this method and it returns the rectangle where this bitmap will be actually placed (with modified position and dimensions aligned to the JPEG sample size).
If you pass an offset which is not aligned, Graphics Mill for .NET automatically aligns it. As a result x and y coordinates of this offset will be rounded down by the JPEG sample size. For example, if you specify the following point (19, 19) to place the bitmap, it will be actually placed into the (16, 16) position (if the JPEG sample size is 8x8 or 16x16). If the bitmap you pass to this method is not aligned, Graphics Mill for .NET automatically aligns it. As a result its dimension will be enlarged to be divisible by the JPEG sample size and the extended area will be filled with garbage.