←Select platform

MemoryFlags Property

Summary
Gets or sets the memory model flags being used to create the RasterImage object.
Syntax
C#
Objective-C
C++/CLI
Java
Python
public RasterMemoryFlags MemoryFlags { get; set; } 
@property (nonatomic, assign) LTRasterMemoryFlags memoryFlags; 
public int getMemoryFlags(); 
public void setMemoryFlags( 
   int intValue 
); 
public: 
property RasterMemoryFlags MemoryFlags { 
   RasterMemoryFlags get(); 
   void set (    RasterMemoryFlags ); 
} 
MemoryFlags # get and set (RasterImageAllocateData) 

Property Value

One or more RasterMemoryFlags enumeration members that represent the memory model to use when creating the RasterImage object.

Remarks

You can inspect and change the memory model (conventional, disk, tiled, etc.) used when creating the RasterImage object by using this property. Refer to the example of the RasterDefaults.SetRasterImageAllocateCallback method.

Example
C#
using Leadtools; 
using Leadtools.Codecs; 
 
 
private void SetRasterImageAllocateCallbackExample() 
{ 
	try 
	{ 
		// Set the LEADTOOLS temporary directory to a value we can watch easily 
		RasterDefaults.TemporaryDirectory = Path.Combine(LEAD_VARS.ImagesDir, @"Temp\LEADTOOLS"); 
 
		// Install a callback to notify us when LEADTOOLS images are created 
		// IMPORTANT: SetRasterImageAllocateCallback is global and not thread safe. It will fire 
		// for each image being created after this point, so if the action you are performing in the 
		// callback requires synchronzation, add the required code. For what this sample is trying 
		// to accomplish, our solution is perfectly safe and no synchronization is needed. 
		RasterDefaults.SetRasterImageAllocateCallback(new RasterImageAllocateCallback(MyRasterImageAllocateCallback)); 
 
		// We want conventional memory and nothing else 
		RasterMemoryFlags flags = RasterMemoryFlags.Conventional | RasterMemoryFlags.NoDisk | RasterMemoryFlags.NoTiled; 
		// Create a huge RasterImage 
		using (RasterImage img = new RasterImage(flags, 20000, 20000, 24, RasterByteOrder.Bgr, RasterViewPerspective.TopLeft, null, null, 0)) 
		{ 
			// Rotate it 90 degrees, this will have a memory size greater than the default 
			// size of conventional memory and cause LEADTOOLS to switch to a disk or tiled memory 
			// model. In the callback below, we instruct LEADTOOLS to only use conventional memory so the command 
			// will throw an out of memory exception as expected. 
			Leadtools.ImageProcessing.RotateCommand cmd = new Leadtools.ImageProcessing.RotateCommand(); 
			cmd.Angle = 90 * 100; 
			// Exception will be thrown inside here: No Memory since our callback 
			// will be called and we instruct LEADTOOLS to not use disk 
			cmd.Run(img); 
		} 
	} 
	catch (Exception ex) 
	{ 
		// Show the error 
		Console.WriteLine(ex.Message); 
	} 
} 
 
private static RasterExceptionCode MyRasterImageAllocateCallback(RasterImageAllocateData data) 
{ 
	Console.WriteLine("Trying to allocate:"); 
	Console.WriteLine("   Memory: {0}", data.MemoryFlags); 
	Console.WriteLine("   Size: {0} by {1}", data.Width, data.Height); 
	Console.WriteLine("   BPP: {0}, Order: {1}", data.BitsPerPixel, data.Order); 
	Console.WriteLine("   Size: {0}", data.Size); 
 
	// Note, all values beside MemoryFlags are read only and cannot be changed 
 
	// We want conventional memory and nothing else, so change this 
	data.MemoryFlags = RasterMemoryFlags.Conventional | RasterMemoryFlags.NoTiled | RasterMemoryFlags.NoDisk; 
 
	// If you remove the code above, the toolkit will most probably switch to disk or tiled memory model 
	// and creating this huge image will be successful, however, we only want conventional 
	// memory in this example, and out of memory exception is the expected behavior of this 
	// example 
 
	// Let LEADTOOLS continue with creating the image process 
	// You can return any other value to abort 
	return RasterExceptionCode.Success; 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images"; 
} 
Requirements

Target Platforms

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

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