Provides the information needed to automatically convert the resolution of digital photos in LEADTOOLS toolkits.
public struct AutoFixImageResolutionOptions Public Structure AutoFixImageResolutionOptions public:value class AutoFixImageResolutionOptions sealed
Automatic resolution conversion is particularly useful in OCR or Document Writer operations.
Typically, a picture taken with a digital camera does not have good resolution information (DPI). (Images originating from scanners have good resolution information, but images from digital cameras do not.) This is because digital cameras usually set the resolution regardless of the width and height of the image captured. The resolution set is an arbitrary number, often 72 DPI.
An example will illustrate the consequences of using an arbitrary DPI. Suppose you take a 12 Megapixels (3000 x 4000) photo with a digital camera. Keeping the original resolution at 72 DPI, the image would be 41.6 x 55.5 inches. If you then convert this image to PDF without adjusting the resolution, it will generate a PDF file that is 41.6 x 55.5 inches. Loaded using a LEADTOOLS document viewer, the image will be loaded onto many pages (5x5 = 25 pages). Most people do not want or expect that. Therefore, it is preferable to adjust the resolution so the image fits inside a single page.
The following methods allow getting and setting the automatic resolution conversion options:
The settings in AutoFixImageResolutionOptions are used under the following conditions:
Directly if RasterImage.AutoFixResolution is called.
Indirectly when using RasterCodecs with any load method (RasterCodecs.Load, RasterCodecs.LoadAync, etc.) if the value of CodecsLoadOptions is true. The load methods use the settings in AutoFixImageResolutionOptions to determine whether the resolution in a file should be automatically updated to fit inside a rectangle of PageWidth x PageHeight in size.
Indirectly if a RasterCodecs.GetInformation (or an equivalent method that retrieves a CodecsImageInfo object for a file whose resolution should be automatically converted) is called. The XResolution and YResolution members will be set to the converted resolution. In addition, CodecsImageInfo will have the IsCorrectedResolution value set to true.
The fit calculation is a smart algorithm that measures the rectangle area, which means that if an image resolution needs to be updated, it will either be adjusted to fit inside a PageWidth x PageHeight rectangle, or in a PageHeight x PageWidth rectangle, whichever fits best.
The following examples assume the following conditions:
AutoFixImageResolutionOptions has been setPageWidth = 8.5PageHeight = 11Unit = AutoFixImageResolutionUnit.Inch (the settings for the US letter paper size)MinResolution = 96If a Load method or RasterImage.AutoFixResolution is called:
The following example shows how to instruct LEADTOOLS to automatically convert the resolution in digital photos (images with a resolution less than 96):
using Leadtools;using Leadtools.Codecs;public static void AutoFixImageResolutionOptions_Example(){// Simulate a digital camera imagestring fileName = Path.Combine(LEAD_VARS.ImagesDir, "digital-camera.jpg");int pixelWidth = 3042;int pixelHeight = 4032;int resolution = 72;using (var rasterImage = RasterImage.Create(pixelWidth, pixelHeight, 24, resolution, RasterColor.White)){using (var codecs = new RasterCodecs()){codecs.Save(rasterImage, fileName, RasterImageFormat.ExifJpeg411, 24);}}Console.WriteLine("Default");// Load it using the default values, it should be the original sizeusing (var codecs = new RasterCodecs()){using (var rasterImage = codecs.Load(fileName, 1)){Console.WriteLine("image size {0} by {1} pixels at {2} DPI", rasterImage.Width, rasterImage.Height, rasterImage.XResolution);// Show its size in inchesdouble inchesWidth = (double)rasterImage.Width / rasterImage.XResolution;double inchesHeight = (double)rasterImage.Height / rasterImage.YResolution;Console.WriteLine("size in inches {0} by {1}", inchesWidth, inchesHeight);Debug.Assert(rasterImage.Width == pixelWidth);Debug.Assert(rasterImage.Height == pixelHeight);Debug.Assert(rasterImage.XResolution == resolution);Debug.Assert(rasterImage.YResolution == resolution);}}Console.WriteLine("Fixing the resolution");// Automatically fix its resolution next time we load itAutoFixImageResolutionOptions options = RasterDefaults.GetAutoFixImageResolutionOptions();options.PageWidth = 8.5;options.PageHeight = 11;options.Unit = AutoFixImageResolutionUnit.Inch;options.MinResolution = 96;RasterDefaults.SetAutoFixImageResolutionOptions(options);using (var codecs = new RasterCodecs()){// Use the option with this RasterCodecscodecs.Options.Load.AutoFixImageResolution = true;using (var rasterImage = codecs.Load(fileName, 1)){Console.WriteLine("image size {0} by {1} pixels at {2} DPI", rasterImage.Width, rasterImage.Height, rasterImage.XResolution);// Show its size in inchesdouble inchesWidth = (double)rasterImage.Width / rasterImage.XResolution;double inchesHeight = (double)rasterImage.Height / rasterImage.YResolution;Console.WriteLine("size in inches {0} by {1}", inchesWidth, inchesHeight);Debug.Assert(rasterImage.Width == pixelWidth);Debug.Assert(rasterImage.Height == pixelHeight);Debug.Assert((int)inchesWidth <= 8.5);Debug.Assert((int)inchesHeight <= 11);}}}static class LEAD_VARS{public const string ImagesDir = @"C:\LEADTOOLS21\Resources\Images";}
Imports LeadtoolsImports Leadtools.CodecsImports Leadtools.ImageProcessingImports Leadtools.ImageProcessing.CoreImports Leadtools.ImageProcessing.ColorImports Leadtools.ControlsImports Leadtools.DicomImports Leadtools.DrawingImports Leadtools.SvgPublic Shared Sub AutoFixImageResolutionOptions_Example()' Simulate a digital camera imageDim fileName As String = Path.Combine(LEAD_VARS.ImagesDir, "digital-camera.jpg")Dim pixelWidth As Integer = 3042Dim pixelHeight As Integer = 4032Dim resolution As Integer = 72Using rasterImage As RasterImage = RasterImage.Create(pixelWidth, pixelHeight, 24, resolution, RasterColor.White)Using codecs As New RasterCodecs()codecs.Save(rasterImage, fileName, RasterImageFormat.ExifJpeg411, 24)End UsingEnd UsingConsole.WriteLine("Default")' Load it using the default values, it should be the original sizeUsing codecs As New RasterCodecs()Using rasterImage As RasterImage = codecs.Load(fileName, 1)Console.WriteLine("image size {0} by {1} pixels at {2} DPI", rasterImage.Width, rasterImage.Height, rasterImage.XResolution)' Show its size in inchesDim inchesWidth As Double = rasterImage.Width / rasterImage.XResolutionDim inchesHeight As Double = rasterImage.Height / rasterImage.YResolutionConsole.WriteLine("size in inches {0} by {1}", inchesWidth, inchesHeight)Debug.Assert(rasterImage.Width = pixelWidth)Debug.Assert(rasterImage.Height = pixelHeight)Debug.Assert(rasterImage.XResolution = resolution)Debug.Assert(rasterImage.YResolution = resolution)End UsingEnd UsingConsole.WriteLine("Fixing the resolution")' Automatically fix its resolution next time we load itDim options As AutoFixImageResolutionOptions = RasterDefaults.GetAutoFixImageResolutionOptions()options.PageWidth = 8.5options.PageHeight = 11options.Unit = AutoFixImageResolutionUnit.Inchoptions.MinResolution = 96RasterDefaults.SetAutoFixImageResolutionOptions(options)Using codecs As New RasterCodecs()' Use the option with this RasterCodecscodecs.Options.Load.AutoFixImageResolution = TrueUsing rasterImage As RasterImage = codecs.Load(fileName, 1)Console.WriteLine("image size {0} by {1} pixels at {2} DPI", rasterImage.Width, rasterImage.Height, rasterImage.XResolution)' Show its size in inchesDim inchesWidth As Double = rasterImage.Width / rasterImage.XResolutionDim inchesHeight As Double = rasterImage.Height / rasterImage.YResolutionConsole.WriteLine("size in inches {0} by {1}", inchesWidth, inchesHeight)Debug.Assert(rasterImage.Width = pixelWidth)Debug.Assert(rasterImage.Height = pixelHeight)Debug.Assert(CType(inchesWidth, Integer) <= 8.5)Debug.Assert(CType(inchesHeight, Integer) <= 11)End UsingEnd UsingEnd SubPublic NotInheritable Class LEAD_VARSPublic Const ImagesDir As String = "C:\LEADTOOLS21\Resources\Images"End Class
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document
