LosslessJpeg Class |
Namespace: Atalasoft.Imaging.ImageProcessing
The LosslessJpeg type exposes the following members.
Name | Description | |
---|---|---|
CanDoLosslessTransform(Stream, JpegTransformType) | Returns a value indicating the the MCU blocks are arranged such that a lossless transformation can be
performed without cropping the image. | |
CanDoLosslessTransform(String, JpegTransformType) | Returns a value indicating the the MCU blocks are arranged such that a lossless transformation can be
performed without cropping the image. | |
Crop(Stream, Stream, Rectangle) | Performs a lossless crop on a JPEG image. | |
Crop(String, String, Rectangle) | Performs a lossless crop on a JPEG image. | |
Crop(Stream, Stream, Rectangle, JpegTransformFlags) | Performs a lossless crop on a JPEG image. | |
Crop(String, String, Rectangle, JpegTransformFlags) | Performs a lossless crop on a JPEG image. | |
Equals | Determines whether the specified object is equal to the current object. (Inherited from Object.) | |
GetHashCode | Serves as the default hash function. (Inherited from Object.) | |
GetMcuBlockSize(Stream) | Get the compression block size for a JPG file. | |
GetMcuBlockSize(String) | Get the compression block size for a JPG file. | |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
ToString | Returns a string that represents the current object. (Inherited from Object.) | |
Transform(Stream, Stream, JpegTransformType) | Perform a lossless transform on a JPEG image. | |
Transform(String, String, JpegTransformType) | Perform a lossless transform on a JPEG image. | |
Transform(Stream, Stream, JpegTransformType, JpegTransformFlags) | Perform a lossless transform on a JPEG image. | |
Transform(String, String, JpegTransformType, JpegTransformFlags) | Perform a lossless transform on a JPEG image. |
JPEG images are compressed with lossy compression, meaning that each time the image is saved, quality is lost. Some operations, such as rotate, crop, and convert to grayscale can be performed without re-encoding the data.
Do determine of the image can be operated on losslessly, check the CanDoLosslessTransform(String, JpegTransformType) method. JPEG images are divided into rectangular sections called MCU blocks that are typically 8x8 pixels. If the width and height are both divisible by 8, then it usually means that lossless operations can be performed without losing or cropping the edges. However some JPEG images have MCU blocks other than 8.
// Load a JPEG image. FileStream fs = new FileStream(@"D:\Test Images\1.jpg", FileMode.Open, FileAccess.Read); // See if the file can use the lossless transform. if (LosslessJpeg.CanDoLosslessTransform(fs, JpegTransformType.Rotate90)) { FileStream fsSave = new FileStream(@"D:\Test Images\1transform.jpg", FileMode.Create, FileAccess.Write); fs.Seek(0, SeekOrigin.Begin); LosslessJpeg.Transform(fs, fsSave, JpegTransformType.Rotate90); fsSave.Close(); } else { // Use the normal rotate command. fs.Seek(0, SeekOrigin.Begin); AtalaImage image = new AtalaImage(fs, null); RotateCommand cmd = new RotateCommand(90); AtalaImage result = cmd.ApplyToImage(image); result.Save(@"D:\Test Images\1transform.jpg", new JpegEncoder(85), null); image.Dispose(); result.Dispose(); } fs.Close();
' Load a JPEG image. Dim fs As FileStream = New FileStream("D:\Test Images\1.jpg", FileMode.Open,FileAccess.Read) ' See if the file can use the lossless transform. If LosslessJpeg.CanDoLosslessTransform(fs,JpegTransformType.Rotate90) Then Dim fsSave As FileStream = New FileStream("D:\Test Images\1transform.jpg", FileMode.Create, FileAccess.Write) fs.Seek(0, SeekOrigin.Begin) LosslessJpeg.Transform(fs, fsSave, JpegTransformType.Rotate90) fsSave.Close() Else ' Use the normal rotate command. fs.Seek(0, SeekOrigin.Begin) Dim image As AtalaImage = New AtalaImage(fs,Nothing) Dim cmd As RotateCommand = New RotateCommand(90) Dim result As AtalaImage = cmd.ApplyToImage(image) result.Save("D:\Test Images\1transform.jpg",New JpegEncoder(85),Nothing) image.Dispose() result.Dispose() End If fs.Close()