This documentation is for the old version. Go to the latest Graphics Mill docs

JPEG File Format

JPEG is a standard image format for storing photos. JPEG stands for Joint Photographic Experts Group, the original name of the committee that wrote this standard. JPEG stores images with lossy compression and it is designed for compressing either full-color or grayscale images of natural, real-world scenes. When writing original image to JPEG, the quality of image can be specified. The lower the specified compression quality is, the lesser size the resulting file will have.

JPEG images support three main color spaces:

  • RGB,
  • CMYK,
  • grayscale.

There is a special type of JPEG images - progressive. Progressive JPEG rearranges the stored image data. When the JPEG file is transmitted across a slow communications link, it allows to decoder to generate a low-quality image very quickly, then gradually improve the displayed quality as more image data are received. The final image is identical to that of a regular JPEG file of the same quality setting. Progressive JPEG files are often slightly larger than non-progressive ones, but the possibility of incremental display is the main reason for using progressive JPEG.

Format Name

JPEG

MIME Type

image/jpeg

File Extensions

*.jpg

Supported Pixel Formats

Description Read Write
8 bit grayscale Yes Yes
24 bit RGB Yes Yes
32 bit CMYK Yes Yes

Metadata Available for Reading

Name Comments
JpegReader.Exif EXIF data collection.
JpegReader.Iptc IPTC data collection.
JpegReader.Xmp XML code containing the XMP metadata.
JpegReader.AdobeResources Adobe® image resource blocks.

Encoder Options

Name Default Value Comments
JpegEncoderOptions.Exif
JpegWriter.Exif
N/A EXIF data collection you want to write into the file.
JpegEncoderOptions.Iptc
JpegWriter.Iptc
N/A IPTC data collection you want to write into the file.
JpegEncoderOptions.Xmp
JpegWriter.Xmp
N/A XML code containing the XMP metadata you want to write into the file.
JpegEncoderOptions.AdobeResources
JpegWriter.AdobeResources
N/A Adobe® image resource blocks you want to write into the file.
JpegEncoderOptions.IsProgressive
JpegFrame.IsProgressive
false Value that specifies if JPEG should be progressive.
JpegEncoderOptions.Quality
JpegFrame.Quality
75 Value in range [0, 100] specifying JPEG quality.

Examples

Loading JPEG Files

The simplest way to load the JPEG file is to pass its name to the constructor:

Visual Basic
Dim bitmap As New Aurigma.GraphicsMill.Bitmap("c:\Mountain.jpg")
C#
Aurigma.GraphicsMill.Bitmap bitmap = new Aurigma.GraphicsMill.Bitmap(@"c:\Mountain.jpg");

Alternatively, if you already have an instance of the Bitmap, you can use Load method:

Visual Basic
Dim bitmap As New Aurigma.GraphicsMill.Bitmap
bitmap.Load("c:\Mountain.jpg")
C#
Aurigma.GraphicsMill.Bitmap bitmap = new Aurigma.GraphicsMill.Bitmap();
bitmap.Load(@"c:\Mountain.jpg");

Saving JPEG files

This code example demonstrates how to save the JPEG file with non-default encoder settings. Here we set low quality and make JPEG to be progressive (good for fast delivery via Web):

Visual Basic
Dim bitmap As New Aurigma.GraphicsMill.Bitmap("c:\Mountain.jpg")

bitmap.Save("C:\Mountain2.jpg", _
    New Aurigma.GraphicsMill.Codecs.JpegEncoderOptions(50, True))

bitmap.Dispose()
C#
using (Aurigma.GraphicsMill.Bitmap bitmap = 
        new Aurigma.GraphicsMill.Bitmap(@"c:\Mountain.jpg"))
{
    bitmap.Save(@"C:\Mountain2.jpg", 
        new Aurigma.GraphicsMill.Codecs.JpegEncoderOptions(50, true));
}

Also you can use JpegWriter class instead of the Save method of the Bitmap. In particular it enables you to save the image asynchronously.

The JpegWriter class usage is demonstrated below:

Visual Basic
Dim bitmap As New Aurigma.GraphicsMill.Bitmap("c:\Mountain.jpg")

Dim writer As New Aurigma.GraphicsMill.Codecs.JpegWriter("C:\Mountain2.jpg")

Dim frame As New Aurigma.GraphicsMill.Codecs.JpegFrame
frame.Quality = 50
frame.IsProgressive = True
frame.SetBitmap(bitmap)

bitmap.Dispose()

writer.AddFrame(frame)

frame.Dispose()

writer.Dispose()
C#
using (Aurigma.GraphicsMill.Bitmap bitmap = 
        new Aurigma.GraphicsMill.Bitmap(@"c:\Mountain.jpg"))
{
    using (Aurigma.GraphicsMill.Codecs.JpegWriter writer = 
            new Aurigma.GraphicsMill.Codecs.JpegWriter(@"C:\Mountain2.jpg"))
    {

        using (Aurigma.GraphicsMill.Codecs.JpegFrame frame = 
                   new Aurigma.GraphicsMill.Codecs.JpegFrame())
        {
            frame.Quality = 50;
            frame.IsProgressive = true;
            frame.SetBitmap(bitmap);

            writer.AddFrame(frame);                
        }

    }
}

Working with Metadata

JPEG files can store EXIF, IPTC, XMP, and Adobe® image resource blocks metadata collections. Graphics Mill for .NET enables you to extract this data from the JPEG file and save it into another JPEG file (as well as into the other file format which supports such kinds of metadata). This code example demonstrates how to add metadata to the file:

Visual Basic
Dim bitmap As New Aurigma.GraphicsMill.Bitmap("c:\Mountain.jpg")

Dim encoderOptions As New Aurigma.GraphicsMill.Codecs.JpegEncoderOptions(50, True)

'EXIF
Dim exif As New Aurigma.GraphicsMill.Codecs.ExifDictionary
exif(Aurigma.GraphicsMill.Codecs.ExifDictionary.Software) = "Aurigma Graphics Mill"
encoderOptions.Exif = exif

'IPTC
Dim iptc As New Aurigma.GraphicsMill.Codecs.IptcDictionary
iptc(Aurigma.GraphicsMill.Codecs.IptcDictionary.Category) = "Nature"
iptc(Aurigma.GraphicsMill.Codecs.IptcDictionary.CopyrightNotice) = "Aurigma Inc."
iptc(Aurigma.GraphicsMill.Codecs.IptcDictionary.Keyword) = "mountain"

encoderOptions.Iptc = iptc

'Adobe resource blocks
Dim adobeResources As New Aurigma.GraphicsMill.Codecs.AdobeResourceDictionary
'Create new adobe image resource block with the required metadata
Dim arBlock As New Aurigma.GraphicsMill.Codecs.AdobeResourceBlock("Copyright", New Byte() {1})
'Set this block to the item with 0x040A ID (copyright flag)
adobeResources.Item(&H40A) = arBlock

encoderOptions.AdobeResources = adobeResources

'XMP
Dim xmp As New Aurigma.GraphicsMill.Codecs.XmpData()
'Create a node with the required metadata
Dim node As New Aurigma.GraphicsMill.Codecs.XmpValueNode( _
    Aurigma.GraphicsMill.Codecs.XmpNodeType.SimpleProperty, _
    "John Doe", _
    Aurigma.GraphicsMill.Codecs.XmpTagNames.DCCreator)
xmp.AddNode(node)

encoderOptions.Xmp = xmp.Save()

bitmap.Save("C:\Mountain2.jpg", encoderOptions)

bitmap.Dispose()
C#
using (Aurigma.GraphicsMill.Bitmap bitmap = 
           new Aurigma.GraphicsMill.Bitmap(@"c:\Mountain.jpg"))
{                
    Aurigma.GraphicsMill.Codecs.JpegEncoderOptions encoderOptions =
        new Aurigma.GraphicsMill.Codecs.JpegEncoderOptions(50, true);

    //EXIF
    Aurigma.GraphicsMill.Codecs.ExifDictionary exif =
        new Aurigma.GraphicsMill.Codecs.ExifDictionary();
    exif[Aurigma.GraphicsMill.Codecs.ExifDictionary.Software] = "Aurigma Graphics Mill";

    encoderOptions.Exif = exif;
    
    //IPTC
    Aurigma.GraphicsMill.Codecs.IptcDictionary iptc =
        new Aurigma.GraphicsMill.Codecs.IptcDictionary();
    iptc[Aurigma.GraphicsMill.Codecs.IptcDictionary.Category] = "Nature";
    iptc[Aurigma.GraphicsMill.Codecs.IptcDictionary.CopyrightNotice] = "Aurigma Inc.";
    iptc[Aurigma.GraphicsMill.Codecs.IptcDictionary.Keyword] = "mountain";

    encoderOptions.Iptc = iptc;

    //Adobe resource blocks
     Aurigma.GraphicsMill.Codecs.AdobeResourceDictionary adobeResources = 
         new Aurigma.GraphicsMill.Codecs.AdobeResourceDictionary();
    //Create new adobe image resource block with the required metadata
    Aurigma.GraphicsMill.Codecs.AdobeResourceBlock arBlock = new
        Aurigma.GraphicsMill.Codecs.AdobeResourceBlock("Copyright", new byte[] { 1 });
    //Set this block to the item with 0x040A ID (copyright flag)
    adobeResources[0x040A] = arBlock;

    encoderOptions.AdobeResources = adobeResources;

    //XMP
    Aurigma.GraphicsMill.Codecs.XmpData xmp = new Aurigma.GraphicsMill.Codecs.XmpData();
    //Create a node with the required metadata
    Aurigma.GraphicsMill.Codecs.XmpValueNode node = new
        Aurigma.GraphicsMill.Codecs.XmpValueNode(
            Aurigma.GraphicsMill.Codecs.XmpNodeType.SimpleProperty,
            "John Doe",
            Aurigma.GraphicsMill.Codecs.XmpTagNames.DCCreator);
    xmp.AddNode(node);

    encoderOptions.Xmp = xmp.Save();

    bitmap.Save(@"C:\Mountain2.jpg", encoderOptions);
}

The code below does the same, but using JpegWriter:

Visual Basic
Dim bitmap As New Aurigma.GraphicsMill.Bitmap("c:\Mountain.jpg")

Dim writer As New Aurigma.GraphicsMill.Codecs.JpegWriter("C:\Mountain2.jpg")

'EXIF
Dim exif As New Aurigma.GraphicsMill.Codecs.ExifDictionary
exif(Aurigma.GraphicsMill.Codecs.ExifDictionary.Software) = "Aurigma Graphics Mill"

writer.Exif = exif

'IPTC
Dim iptc As New Aurigma.GraphicsMill.Codecs.IptcDictionary
iptc(Aurigma.GraphicsMill.Codecs.IptcDictionary.Category) = "Nature"
iptc(Aurigma.GraphicsMill.Codecs.IptcDictionary.CopyrightNotice) = "Aurigma Inc."
iptc(Aurigma.GraphicsMill.Codecs.IptcDictionary.Keyword) = "mountain"

writer.Iptc = iptc

'Adobe resource blocks
Dim adobeResources As New Aurigma.GraphicsMill.Codecs.AdobeResourceDictionary
'Create new adobe image resource block with the required metadata
Dim arBlock As New Aurigma.GraphicsMill.Codecs.AdobeResourceBlock("Copyright", New Byte() {1})
'Set this block to the item with 0x040A ID (copyright flag)
adobeResources.Item(&H40A) = arBlock

writer.AdobeResources = adobeResources

'XMP
Dim xmp As New Aurigma.GraphicsMill.Codecs.XmpData()
'Create a node with the required metadata
Dim node As New Aurigma.GraphicsMill.Codecs.XmpValueNode( _
    Aurigma.GraphicsMill.Codecs.XmpNodeType.SimpleProperty, _
    "John Doe", _
    Aurigma.GraphicsMill.Codecs.XmpTagNames.DCCreator)
xmp.AddNode(node)

writer.Xmp = xmp.Save()

Dim frame As New Aurigma.GraphicsMill.Codecs.JpegFrame(50, True)

frame.SetBitmap(bitmap)

bitmap.Dispose()

writer.AddFrame(frame)

frame.Dispose()

writer.Dispose()
C#
using (Aurigma.GraphicsMill.Bitmap bitmap = 
           new Aurigma.GraphicsMill.Bitmap(@"c:\Mountain.jpg"))
{                
    using (Aurigma.GraphicsMill.Codecs.JpegWriter writer = 
               new Aurigma.GraphicsMill.Codecs.JpegWriter(@"C:\Mountain2.jpg"))
    {
        //EXIF
        Aurigma.GraphicsMill.Codecs.ExifDictionary exif =
            new Aurigma.GraphicsMill.Codecs.ExifDictionary();
        exif[Aurigma.GraphicsMill.Codecs.ExifDictionary.Software] = "Aurigma Graphics Mill";

        writer.Exif = exif;
    
        //IPTC
        Aurigma.GraphicsMill.Codecs.IptcDictionary iptc =
            new Aurigma.GraphicsMill.Codecs.IptcDictionary();
        iptc[Aurigma.GraphicsMill.Codecs.IptcDictionary.Category] = "Nature";
        iptc[Aurigma.GraphicsMill.Codecs.IptcDictionary.CopyrightNotice] = "Aurigma Inc.";
        iptc[Aurigma.GraphicsMill.Codecs.IptcDictionary.Keyword] = "mountain";

        writer.Iptc = iptc;

        //Adobe resource blocks
        Aurigma.GraphicsMill.Codecs.AdobeResourceDictionary adobeResources =
            new Aurigma.GraphicsMill.Codecs.AdobeResourceDictionary();
        //Create new adobe image resource block with the required metadata
        Aurigma.GraphicsMill.Codecs.AdobeResourceBlock arBlock = new
            Aurigma.GraphicsMill.Codecs.AdobeResourceBlock("Copyright", new byte[] { 1 });
        //Set this block to the item with 0x040A ID (copyright flag)
        adobeResources[0x040A] = arBlock;

        writer.AdobeResources = adobeResources;

        //XMP
        Aurigma.GraphicsMill.Codecs.XmpData xmp = new Aurigma.GraphicsMill.Codecs.XmpData();
        //Create a node with the required metadata
        Aurigma.GraphicsMill.Codecs.XmpValueNode node = new
            Aurigma.GraphicsMill.Codecs.XmpValueNode(
                Aurigma.GraphicsMill.Codecs.XmpNodeType.SimpleProperty,
                "John Doe",
                Aurigma.GraphicsMill.Codecs.XmpTagNames.DCCreator);
        xmp.AddNode(node);

        writer.Xmp = xmp.Save();

        using (Aurigma.GraphicsMill.Codecs.JpegFrame frame = 
                   new Aurigma.GraphicsMill.Codecs.JpegFrame(50, true))
        {
            frame.SetBitmap(bitmap);

            writer.AddFrame(frame);
        }
    }
}