LEADTOOLS Image File Support (Leadtools.Codecs assembly)
LEAD Technologies, Inc

CodecsJpegOptions Class

Example 





Members 
Provides extra options for loading and saving JPEG and LEAD CMP images. .NET support WinRT support Silverlight support
Object Model
CodecsJpegOptions ClassCodecsJpegLoadOptions ClassCodecsJpegSaveOptions Class
Syntax
public class CodecsJpegOptions 
'Declaration
 
Public Class CodecsJpegOptions 
'Usage
 
Dim instance As CodecsJpegOptions
public sealed class CodecsJpegOptions 
function Leadtools.Codecs.CodecsJpegOptions()
public ref class CodecsJpegOptions 
Example
 
Public Sub CodecsJpegOptionsExample()
      Dim codecs As RasterCodecs = New RasterCodecs()

      Dim srcFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Slave.jpg")

      ' Get all Information about the Jpeg file that you want to load.
      Dim imageInfo As CodecsImageInfo = codecs.GetInformation(srcFileName, True)

      'Setting Jpeg Load options.
      codecs.Options.Jpeg.Load.DisableMmx = False
      codecs.Options.Jpeg.Load.DisableP3 = False
      codecs.Options.Jpeg.Load.ForceCieLab = True
      codecs.Options.Jpeg.Load.ForceRgbFile = False
      codecs.Options.Jpeg.Load.UseBadJpegPredictor = False

      Dim srcImage As RasterImage = codecs.Load(srcFileName)

      'if the image has stamp then set the Jpeg settings related to the stamp.
      If imageInfo.Jpeg.HasStamp Then
         codecs.Options.Jpeg.Save.FixedPaletteStamp = True
         codecs.Options.Jpeg.Save.JpegStamp = True
         codecs.Options.Jpeg.Save.SaveWithoutTimestamp = False
         codecs.Options.Jpeg.Save.SaveWithStamp = True
         codecs.Options.Jpeg.Save.StampBitsPerPixel = srcImage.BitsPerPixel
         codecs.Options.Jpeg.Save.StampHeight = 100
         codecs.Options.Jpeg.Save.StampWidth = 100
         codecs.Options.Jpeg.Save.YccStamp = False
      End If

      If imageInfo.Jpeg.IsLossless Then
         Console.WriteLine("This is a lossless Jpeg Image")
      Else
         Console.WriteLine("This is not a lossless Jpeg Image")
      End If

      If imageInfo.Jpeg.IsProgressive Then
         codecs.Options.Jpeg.Save.Passes = 0
      End If

      codecs.Options.Jpeg.Save.CmpQualityFactorPredefined = CodecsCmpQualityFactorPredefined.Custom
      codecs.Options.Jpeg.Save.DisableMmx = True
      codecs.Options.Jpeg.Save.DisableP3 = True
      codecs.Options.Jpeg.Save.QualityFactor = 2
      codecs.Options.Jpeg.Save.SaveOldJtif = True

      codecs.Save(srcImage, Path.Combine(LEAD_VARS.ImagesDir, "jpeg1.jpg"), RasterImageFormat.Jpeg, srcImage.BitsPerPixel)

      codecs.Options.Jpeg.Save.FixedPaletteStamp = False
      codecs.Options.Jpeg.Save.JpegStamp = True
      codecs.Options.Jpeg.Save.SaveWithoutTimestamp = True
      codecs.Options.Jpeg.Save.SaveWithStamp = True
      codecs.Options.Jpeg.Save.StampBitsPerPixel = srcImage.BitsPerPixel
      codecs.Options.Jpeg.Save.StampHeight = 75
      codecs.Options.Jpeg.Save.StampWidth = 50
      codecs.Options.Jpeg.Save.YccStamp = True
      codecs.Options.Jpeg.Save.CmpQualityFactorPredefined = CodecsCmpQualityFactorPredefined.MaximumQuality
      codecs.Options.Jpeg.Save.DisableMmx = False
      codecs.Options.Jpeg.Save.DisableP3 = False
      codecs.Options.Jpeg.Save.SaveOldJtif = False

      codecs.Save(srcImage, Path.Combine(LEAD_VARS.ImagesDir, "jpeg2.jpg"), RasterImageFormat.Jpeg, srcImage.BitsPerPixel)

      ' Clean up
      srcImage.Dispose()
      codecs.Dispose()
   End Sub

Public NotInheritable Class LEAD_VARS
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
public void CodecsJpegOptionsExample()
     {
         RasterCodecs codecs = new RasterCodecs();

         string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "cannon.jpg");

         // Get all Information about the Jpeg file that you want to load.
         CodecsImageInfo imageInfo = codecs.GetInformation(srcFileName, true);

         //Setting Jpeg Load options.
         codecs.Options.Jpeg.Load.DisableMmx = false;
         codecs.Options.Jpeg.Load.DisableP3 = false;
         codecs.Options.Jpeg.Load.ForceCieLab = true;
         codecs.Options.Jpeg.Load.ForceRgbFile = false;
         codecs.Options.Jpeg.Load.UseBadJpegPredictor = false;

         RasterImage srcImage = codecs.Load(srcFileName);

         //if the image has stamp then set the Jpeg settings related to the stamp.
         if (imageInfo.Jpeg.HasStamp)
         {
             codecs.Options.Jpeg.Save.FixedPaletteStamp = true;
             codecs.Options.Jpeg.Save.JpegStamp = true;
             codecs.Options.Jpeg.Save.SaveWithoutTimestamp = false;
             codecs.Options.Jpeg.Save.SaveWithStamp = true;
             codecs.Options.Jpeg.Save.StampBitsPerPixel = srcImage.BitsPerPixel;
             codecs.Options.Jpeg.Save.StampHeight = 100;
             codecs.Options.Jpeg.Save.StampWidth = 100;
             codecs.Options.Jpeg.Save.YccStamp = false;
         }

         if (imageInfo.Jpeg.IsLossless)
             Console.WriteLine("This is a lossless Jpeg Image");
         else
             Console.WriteLine("This is not a lossless Jpeg Image");

         if (imageInfo.Jpeg.IsProgressive)
             codecs.Options.Jpeg.Save.Passes = 0;

         codecs.Options.Jpeg.Save.CmpQualityFactorPredefined = CodecsCmpQualityFactorPredefined.Custom;
         codecs.Options.Jpeg.Save.DisableMmx = true;
         codecs.Options.Jpeg.Save.DisableP3 = true;
         codecs.Options.Jpeg.Save.QualityFactor = 2;
         codecs.Options.Jpeg.Save.SaveOldJtif = true;

         codecs.Save(srcImage, Path.Combine(LEAD_VARS.ImagesDir, "jpeg1.jpg"), RasterImageFormat.Jpeg, srcImage.BitsPerPixel);

         codecs.Options.Jpeg.Save.FixedPaletteStamp = false;
         codecs.Options.Jpeg.Save.JpegStamp = true;
         codecs.Options.Jpeg.Save.SaveWithoutTimestamp = true;
         codecs.Options.Jpeg.Save.SaveWithStamp = true;
         codecs.Options.Jpeg.Save.StampBitsPerPixel = srcImage.BitsPerPixel;
         codecs.Options.Jpeg.Save.StampHeight = 75;
         codecs.Options.Jpeg.Save.StampWidth = 50;
         codecs.Options.Jpeg.Save.YccStamp = true;
         codecs.Options.Jpeg.Save.CmpQualityFactorPredefined = CodecsCmpQualityFactorPredefined.MaximumQuality;
         codecs.Options.Jpeg.Save.DisableMmx = false;
         codecs.Options.Jpeg.Save.DisableP3 = false;
         codecs.Options.Jpeg.Save.SaveOldJtif = false;

         codecs.Save(srcImage, Path.Combine(LEAD_VARS.ImagesDir, "jpeg2.jpg"), RasterImageFormat.Jpeg, srcImage.BitsPerPixel);

         // Clean up
         srcImage.Dispose();
         codecs.Dispose();
     }

static class LEAD_VARS
{
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
CodecsOptionsExamples.prototype.CodecsJpegOptionsExample = function ( ) 
{
   Tools.SetLicense ( ) ;
   with (Leadtools) {
      with (Leadtools.Codecs) {
         var codecs = new RasterCodecs();

         var srcFileName = "Assets\\cannon.jpg";
         var imageInfo;
         var srcImage;
         // Get all Information about the Jpeg file that you want to load.
         return Tools.AppInstallFolder().getFileAsync(srcFileName).then(function (loadFile) {
            return codecs.getInformationAsync(LeadStreamFactory.create(loadFile), true, 1)
         }).then(function (imageInfoX) {
            imageInfo = imageInfoX;

            //Setting Jpeg Load options.
            codecs.options.jpeg.load.disableMmx = false;
            codecs.options.jpeg.load.disableP3 = false;
            codecs.options.jpeg.load.forceCieLab = true;
            codecs.options.jpeg.load.forceRgbFile = false;
            codecs.options.jpeg.load.useBadJpegPredictor = false;

            return Tools.AppInstallFolder().getFileAsync(srcFileName)
         }).then(function (loadFile) {
            return codecs.loadAsync(LeadStreamFactory.create(loadFile))
         })
         .then(function (srcImg) {
            srcImage = srcImg;
            //if the image has stamp then set the Jpeg settings related to the stamp.
            if (imageInfo.jpeg.hasStamp) {
               codecs.options.jpeg.save.fixedPaletteStamp = true;
               codecs.options.jpeg.save.jpegStamp = true;
               codecs.options.jpeg.save.saveWithoutTimestamp = false;
               codecs.options.jpeg.save.saveWithStamp = true;
               codecs.options.jpeg.save.stampBitsPerPixel = srcImage.bitsPerPixel;
               codecs.options.jpeg.save.stampHeight = 100;
               codecs.options.jpeg.save.stampWidth = 100;
               codecs.options.jpeg.save.yccStamp = false;
            }

            if (imageInfo.jpeg.isLossless)
               console.info("This is a lossless Jpeg Image");
            else
               console.info("This is not a lossless Jpeg Image");

            if (imageInfo.jpeg.isProgressive)
               codecs.options.jpeg.save.passes = 0;

            codecs.options.jpeg.save.cmpQualityFactorPredefined = CodecsCmpQualityFactorPredefined.custom;
            codecs.options.jpeg.save.disableMmx = true;
            codecs.options.jpeg.save.disableP3 = true;
            codecs.options.jpeg.save.qualityFactor = 2;
            codecs.options.jpeg.save.saveOldJtif = true;

            var destFileName = "jpeg1.jpg";
            return Tools.AppLocalFolder().createFileAsync(destFileName)
         })
         .then(function (saveFile) {
            return codecs.saveAsync(srcImage, LeadStreamFactory.create(saveFile), RasterImageFormat.jpeg, srcImage.bitsPerPixel)
         })
         .then(function () {

            codecs.options.jpeg.save.fixedPaletteStamp = false;
            codecs.options.jpeg.save.jpegStamp = true;
            codecs.options.jpeg.save.saveWithoutTimestamp = true;
            codecs.options.jpeg.save.saveWithStamp = true;
            codecs.options.jpeg.save.stampBitsPerPixel = srcImage.bitsPerPixel;
            codecs.options.jpeg.save.stampHeight = 75;
            codecs.options.jpeg.save.stampWidth = 50;
            codecs.options.jpeg.save.yccStamp = true;
            codecs.options.jpeg.save.cmpQualityFactorPredefined = CodecsCmpQualityFactorPredefined.maximumQuality;
            codecs.options.jpeg.save.disableMmx = false;
            codecs.options.jpeg.save.disableP3 = false;
            codecs.options.jpeg.save.saveOldJtif = false;

            destFileName = "jpeg2.jpg";
            return Tools.AppLocalFolder().createFileAsync(destFileName)
         })
         .then(function (saveFile) {
            return codecs.saveAsync(srcImage, LeadStreamFactory.create(saveFile), RasterImageFormat.jpeg, srcImage.bitsPerPixel)
         })
         .then(function () {

            // Clean up
            srcImage.close();
            codecs.close();
         });
      }
   }
}
[TestMethod]
public async Task CodecsJpegOptionsExample()
{
   RasterCodecs codecs = new RasterCodecs();
   string srcFileName = @"Assets\cannon.jpg";

   // Get all Information about the Jpeg file that you want to load.
   StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName);
   CodecsImageInfo imageInfo = await codecs.GetInformationAsync(LeadStreamFactory.Create(loadFile), true, 1);

   //Setting Jpeg Load options.
   codecs.Options.Jpeg.Load.DisableMmx = false;
   codecs.Options.Jpeg.Load.DisableP3 = false;
   codecs.Options.Jpeg.Load.ForceCieLab = true;
   codecs.Options.Jpeg.Load.ForceRgbFile = false;
   codecs.Options.Jpeg.Load.UseBadJpegPredictor = false;

   loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName);
   RasterImage srcImage = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile));

   //if the image has stamp then set the Jpeg settings related to the stamp.
   if (imageInfo.Jpeg.HasStamp)
   {
      codecs.Options.Jpeg.Save.FixedPaletteStamp = true;
      codecs.Options.Jpeg.Save.JpegStamp = true;
      codecs.Options.Jpeg.Save.SaveWithoutTimestamp = false;
      codecs.Options.Jpeg.Save.SaveWithStamp = true;
      codecs.Options.Jpeg.Save.StampBitsPerPixel = srcImage.BitsPerPixel;
      codecs.Options.Jpeg.Save.StampHeight = 100;
      codecs.Options.Jpeg.Save.StampWidth = 100;
      codecs.Options.Jpeg.Save.YccStamp = false;
   }

   if (imageInfo.Jpeg.IsLossless)
      Debug.WriteLine("This is a lossless Jpeg Image");
   else
      Debug.WriteLine("This is not a lossless Jpeg Image");

   if (imageInfo.Jpeg.IsProgressive)
      codecs.Options.Jpeg.Save.Passes = 0;

   codecs.Options.Jpeg.Save.CmpQualityFactorPredefined = CodecsCmpQualityFactorPredefined.Custom;
   codecs.Options.Jpeg.Save.DisableMmx = true;
   codecs.Options.Jpeg.Save.DisableP3 = true;
   codecs.Options.Jpeg.Save.QualityFactor = 2;
   codecs.Options.Jpeg.Save.SaveOldJtif = true;

   string destFileName = @"jpeg1.jpg";
   StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(destFileName);
   await codecs.SaveAsync(srcImage, LeadStreamFactory.Create(saveFile), RasterImageFormat.Jpeg, srcImage.BitsPerPixel);

   codecs.Options.Jpeg.Save.FixedPaletteStamp = false;
   codecs.Options.Jpeg.Save.JpegStamp = true;
   codecs.Options.Jpeg.Save.SaveWithoutTimestamp = true;
   codecs.Options.Jpeg.Save.SaveWithStamp = true;
   codecs.Options.Jpeg.Save.StampBitsPerPixel = srcImage.BitsPerPixel;
   codecs.Options.Jpeg.Save.StampHeight = 75;
   codecs.Options.Jpeg.Save.StampWidth = 50;
   codecs.Options.Jpeg.Save.YccStamp = true;
   codecs.Options.Jpeg.Save.CmpQualityFactorPredefined = CodecsCmpQualityFactorPredefined.MaximumQuality;
   codecs.Options.Jpeg.Save.DisableMmx = false;
   codecs.Options.Jpeg.Save.DisableP3 = false;
   codecs.Options.Jpeg.Save.SaveOldJtif = false;

   destFileName = @"jpeg2.jpg";
   saveFile = await Tools.AppLocalFolder.CreateFileAsync(destFileName);
   await codecs.SaveAsync(srcImage, LeadStreamFactory.Create(saveFile), RasterImageFormat.Jpeg, srcImage.BitsPerPixel);

   // Clean up
   srcImage.Dispose();
   codecs.Dispose();
}
public void CodecsJpegOptionsExample(Stream inStream, Stream outStreamJpeg1, Stream outStreamJpeg2)
{
   RasterCodecs codecs = new RasterCodecs();
   // Get all Information about the Jpeg file that you want to load.
   CodecsImageInfo imageInfo = codecs.GetInformation(inStream, true);

   //Setting Jpeg Load options.
   codecs.Options.Jpeg.Load.DisableMmx = false;
   codecs.Options.Jpeg.Load.DisableP3 = false;
   codecs.Options.Jpeg.Load.ForceCieLab = true;
   codecs.Options.Jpeg.Load.ForceRgbFile = false;
   codecs.Options.Jpeg.Load.UseBadJpegPredictor = false;

   RasterImage srcImage = codecs.Load(inStream);

   //if the image has stamp then set the Jpeg settings related to the stamp.
   if (imageInfo.Jpeg.HasStamp)
   {
      codecs.Options.Jpeg.Save.FixedPaletteStamp = true;
      codecs.Options.Jpeg.Save.JpegStamp = true;
      codecs.Options.Jpeg.Save.SaveWithoutTimestamp = false;
      codecs.Options.Jpeg.Save.SaveWithStamp = true;
      codecs.Options.Jpeg.Save.StampBitsPerPixel = srcImage.BitsPerPixel;
      codecs.Options.Jpeg.Save.StampHeight = 100;
      codecs.Options.Jpeg.Save.StampWidth = 100;
      codecs.Options.Jpeg.Save.YccStamp = false;
   }

   if (imageInfo.Jpeg.IsLossless)
      Console.WriteLine("This is a lossless Jpeg Image");
   else
      Console.WriteLine("This is not a lossless Jpeg Image");

   if (imageInfo.Jpeg.IsProgressive)
      codecs.Options.Jpeg.Save.Passes = 0;

   codecs.Options.Jpeg.Save.CmpQualityFactorPredefined = CodecsCmpQualityFactorPredefined.Custom;
   codecs.Options.Jpeg.Save.DisableMmx = true;
   codecs.Options.Jpeg.Save.DisableP3 = true;
   codecs.Options.Jpeg.Save.QualityFactor = 2;
   codecs.Options.Jpeg.Save.SaveOldJtif = true;

   codecs.Save(srcImage, outStreamJpeg1, RasterImageFormat.Jpeg, srcImage.BitsPerPixel);

   codecs.Options.Jpeg.Save.FixedPaletteStamp = false;
   codecs.Options.Jpeg.Save.JpegStamp = true;
   codecs.Options.Jpeg.Save.SaveWithoutTimestamp = true;
   codecs.Options.Jpeg.Save.SaveWithStamp = true;
   codecs.Options.Jpeg.Save.StampBitsPerPixel = srcImage.BitsPerPixel;
   codecs.Options.Jpeg.Save.StampHeight = 75;
   codecs.Options.Jpeg.Save.StampWidth = 50;
   codecs.Options.Jpeg.Save.YccStamp = true;
   codecs.Options.Jpeg.Save.CmpQualityFactorPredefined = CodecsCmpQualityFactorPredefined.MaximumQuality;
   codecs.Options.Jpeg.Save.DisableMmx = false;
   codecs.Options.Jpeg.Save.DisableP3 = false;
   codecs.Options.Jpeg.Save.SaveOldJtif = false;

   codecs.Save(srcImage, outStreamJpeg2, RasterImageFormat.Jpeg, srcImage.BitsPerPixel);

   // Clean up
   srcImage.Dispose();
}
Public Sub CodecsJpegOptionsExample(ByVal inStream As Stream, ByVal outStreamJpeg1 As Stream, ByVal outStreamJpeg2 As Stream)
   Dim codecs As RasterCodecs = New RasterCodecs()
   ' Get all Information about the Jpeg file that you want to load.
   Dim imageInfo As CodecsImageInfo = codecs.GetInformation(inStream, True)

   'Setting Jpeg Load options.
   codecs.Options.Jpeg.Load.DisableMmx = False
   codecs.Options.Jpeg.Load.DisableP3 = False
   codecs.Options.Jpeg.Load.ForceCieLab = True
   codecs.Options.Jpeg.Load.ForceRgbFile = False
   codecs.Options.Jpeg.Load.UseBadJpegPredictor = False

   Dim srcImage As RasterImage = codecs.Load(inStream)

   'if the image has stamp then set the Jpeg settings related to the stamp.
   If imageInfo.Jpeg.HasStamp Then
      codecs.Options.Jpeg.Save.FixedPaletteStamp = True
      codecs.Options.Jpeg.Save.JpegStamp = True
      codecs.Options.Jpeg.Save.SaveWithoutTimestamp = False
      codecs.Options.Jpeg.Save.SaveWithStamp = True
      codecs.Options.Jpeg.Save.StampBitsPerPixel = srcImage.BitsPerPixel
      codecs.Options.Jpeg.Save.StampHeight = 100
      codecs.Options.Jpeg.Save.StampWidth = 100
      codecs.Options.Jpeg.Save.YccStamp = False
   End If

   If imageInfo.Jpeg.IsLossless Then
      Console.WriteLine("This is a lossless Jpeg Image")
   Else
      Console.WriteLine("This is not a lossless Jpeg Image")
   End If

   If imageInfo.Jpeg.IsProgressive Then
      codecs.Options.Jpeg.Save.Passes = 0
   End If

   codecs.Options.Jpeg.Save.CmpQualityFactorPredefined = CodecsCmpQualityFactorPredefined.Custom
   codecs.Options.Jpeg.Save.DisableMmx = True
   codecs.Options.Jpeg.Save.DisableP3 = True
   codecs.Options.Jpeg.Save.QualityFactor = 2
   codecs.Options.Jpeg.Save.SaveOldJtif = True

   codecs.Save(srcImage, outStreamJpeg1, RasterImageFormat.Jpeg, srcImage.BitsPerPixel)

   codecs.Options.Jpeg.Save.FixedPaletteStamp = False
   codecs.Options.Jpeg.Save.JpegStamp = True
   codecs.Options.Jpeg.Save.SaveWithoutTimestamp = True
   codecs.Options.Jpeg.Save.SaveWithStamp = True
   codecs.Options.Jpeg.Save.StampBitsPerPixel = srcImage.BitsPerPixel
   codecs.Options.Jpeg.Save.StampHeight = 75
   codecs.Options.Jpeg.Save.StampWidth = 50
   codecs.Options.Jpeg.Save.YccStamp = True
   codecs.Options.Jpeg.Save.CmpQualityFactorPredefined = CodecsCmpQualityFactorPredefined.MaximumQuality
   codecs.Options.Jpeg.Save.DisableMmx = False
   codecs.Options.Jpeg.Save.DisableP3 = False
   codecs.Options.Jpeg.Save.SaveOldJtif = False

   codecs.Save(srcImage, outStreamJpeg2, RasterImageFormat.Jpeg, srcImage.BitsPerPixel)

   ' Clean up
   srcImage.Dispose()
End Sub
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

CodecsJpegOptions Members
Leadtools.Codecs Namespace
Compression Using LEAD and JPEG Formats

 

 


Products | Support | Contact Us | Copyright Notices

© 2006-2012 All Rights Reserved. LEAD Technologies, Inc.