Click or drag to resize

LosslessJpeg Class

Summary description for LosslessJpeg.
This class performs lossless transformations on JPEG images.
Inheritance Hierarchy
SystemObject
  Atalasoft.Imaging.ImageProcessingLosslessJpeg

Namespace:  Atalasoft.Imaging.ImageProcessing
Assembly:  Atalasoft.dotImage (in Atalasoft.dotImage.dll) Version: 11.4.0.9.0.377 (.NET 4.5.2, x86)
Syntax
public sealed class LosslessJpeg

The LosslessJpeg type exposes the following members.

Methods
  NameDescription
Public methodStatic memberCanDoLosslessTransform(Stream, JpegTransformType)
Returns a value indicating the the MCU blocks are arranged such that a lossless transformation can be performed without cropping the image.
Public methodStatic memberCanDoLosslessTransform(String, JpegTransformType)
Returns a value indicating the the MCU blocks are arranged such that a lossless transformation can be performed without cropping the image.
Public methodStatic memberCrop(Stream, Stream, Rectangle)
Performs a lossless crop on a JPEG image.
Public methodStatic memberCrop(String, String, Rectangle)
Performs a lossless crop on a JPEG image.
Public methodStatic memberCrop(Stream, Stream, Rectangle, JpegTransformFlags)
Performs a lossless crop on a JPEG image.
Public methodStatic memberCrop(String, String, Rectangle, JpegTransformFlags)
Performs a lossless crop on a JPEG image.
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodStatic memberGetMcuBlockSize(Stream)
Get the compression block size for a JPG file.
Public methodStatic memberGetMcuBlockSize(String)
Get the compression block size for a JPG file.
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Public methodStatic memberCode exampleTransform(Stream, Stream, JpegTransformType)
Perform a lossless transform on a JPEG image.
Public methodStatic memberCode exampleTransform(String, String, JpegTransformType)
Perform a lossless transform on a JPEG image.
Public methodStatic memberCode exampleTransform(Stream, Stream, JpegTransformType, JpegTransformFlags)
Perform a lossless transform on a JPEG image.
Public methodStatic memberCode exampleTransform(String, String, JpegTransformType, JpegTransformFlags)
Perform a lossless transform on a JPEG image.
Top
Remarks

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.

Examples
LosslessJpeg Example (C#)
// 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();
LosslessJpeg Example (Visual Basic)
' 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()
See Also