←Select platform

SetAutoFixImageResolutionOptions Method

Summary

Sets the automatic resolution conversion options used by LEADTOOLS to automatically convert the resolution of digital photos.

Syntax
C#
C++/CLI
Python
public static void SetAutoFixImageResolutionOptions( 
   AutoFixImageResolutionOptions value 
) 
public:  
   static void SetAutoFixImageResolutionOptions( 
      AutoFixImageResolutionOptions^ value 
   ) 
def SetAutoFixImageResolutionOptions(self,value): 

Parameters

value

The automatic resolution conversion options used by LEADTOOLS to automatically convert the resolution of digital photos.

Remarks

The options set by this method are global (valid for all the threads).

Use RasterDefaults.GetAutoFixImageResolutionOptions.

For more information, refer to AutoFixImageResolutionOptions.

Example
C#
Java
using Leadtools; 
using Leadtools.Codecs; 
 
 
public static void AutoFixImageResolutionOptions_Example() 
{ 
	// Simulate a digital camera image 
	string 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 size 
	using (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 inches 
			double 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 it 
	AutoFixImageResolutionOptions 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 RasterCodecs 
		codecs.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 inches 
			double 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:\LEADTOOLS23\Resources\Images"; 
} 
 
import java.io.File; 
import java.io.IOException; 
import java.nio.file.Files; 
import java.nio.file.Path; 
import java.nio.file.Paths; 
 
import org.junit.*; 
import org.junit.Test; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
import static org.junit.Assert.*; 
 
import leadtools.*; 
import leadtools.codecs.*; 
 
 
public void rasterDefaultsAutoFixImageResolutionOptionsExample() { 
   // Simulate a digital camera image 
   final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
   String fileName = combine(LEAD_VARS_IMAGES_DIR, "digital-camera.jpg"); 
   int pixelWidth = 3042; 
   int pixelHeight = 4032; 
   int resolution = 72; 
   RasterImage rasterImage = RasterImage.create(pixelWidth, pixelHeight, 24, resolution, RasterColor.WHITE); 
   RasterCodecs codecs = new RasterCodecs(); 
   codecs.save(rasterImage, fileName, RasterImageFormat.EXIF_JPEG_411, 24); 
 
   System.out.println("Default"); 
 
   // Load it using the default values, it should be the original size 
   RasterImage rasterImage2 = codecs.load(fileName, 1); 
   System.out.printf("image size %d by %d pixels at %d DPI\n", rasterImage2.getWidth(), rasterImage2.getHeight(), 
         rasterImage2.getXResolution()); 
 
   // Show its size in inches 
   double inchesWidth = (double) rasterImage2.getWidth() / rasterImage2.getXResolution(); 
   double inchesHeight = (double) rasterImage2.getHeight() / rasterImage2.getYResolution(); 
   System.out.printf("size in inches %f by %f", inchesWidth, inchesHeight); 
   assertTrue(rasterImage2.getWidth() == pixelWidth); 
   assertTrue(rasterImage2.getHeight() == pixelHeight); 
   assertTrue(rasterImage2.getXResolution() == resolution); 
   assertTrue(rasterImage2.getYResolution() == resolution); 
 
   System.out.println("Fixing the resolution"); 
 
   // Automatically fix its resolution next time we load it 
   AutoFixImageResolutionOptions options = RasterDefaults.getAutoFixImageResolutionOptions(); 
   options.setPageWidth(8.5); 
   options.setPageHeight(11); 
   options.setUnit(AutoFixImageResolutionUnit.INCH); 
   options.setMinResolution(96); 
   RasterDefaults.setAutoFixImageResolutionOptions(options); 
 
   // Use the option with this RasterCodecs 
   codecs.getOptions().getLoad().setAutoFixImageResolution(true); 
   RasterImage rasterImage3 = codecs.load(fileName, 1); 
   System.out.printf("image size %d by %d pixels at %d DPI", rasterImage3.getWidth(), rasterImage3.getHeight(), 
         rasterImage3.getXResolution()); 
   // Show its size in inches 
   double inchesWidth2 = (double) rasterImage3.getWidth() / rasterImage3.getXResolution(); 
   double inchesHeight2 = (double) rasterImage3.getHeight() / rasterImage3.getYResolution(); 
   System.out.printf("size in inches %f by %f", inchesWidth, inchesHeight); 
   assertTrue(rasterImage3.getWidth() == pixelWidth); 
   assertTrue(rasterImage3.getHeight() == pixelHeight); 
   assertTrue((int) inchesWidth2 <= 8.5); 
   assertTrue((int) inchesHeight2 <= 11); 
} 
Requirements

Target Platforms

Help Version 23.0.2024.5.22
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

Leadtools Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.