←Select platform

Data Property

Summary
Gets the data for the image in native format.
Syntax
C#
Objective-C
C++/CLI
Java
Python
public object Data { get; } 
@property (nonatomic, assign, readonly, nullable) const NSData *data 
public java.lang.Object getData(); 
public: 
property Object^ Data { 
   Object^ get(); 
} 
Data # get  (RasterImage) 

Property Value

The data for the image.

Remarks

This value should only be used with images created with user-defined data. Other type of images will return an undefined internal value.

Example
C#
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Core; 
using Leadtools.ImageProcessing.Color; 
using Leadtools.Dicom; 
using Leadtools.Drawing; 
using Leadtools.Controls; 
using Leadtools.Svg; 
 
 
public void DataExample() 
{ 
	RasterCodecs codecs = new RasterCodecs(); 
 
	string destFileName = Path.Combine(LEAD_VARS.ImagesDir, "Data.bmp"); 
 
	// Create an image with user defined data 
	int width = 40; 
	int height = 40; 
	int bitsPerPixel = 24; 
	int size = width * height * 3; 
	IntPtr data1 = Marshal.AllocHGlobal(size); 
 
	// Load the image 
	RasterImage image = new RasterImage( 
	   RasterMemoryFlags.User, 
	   width, 
	   height, 
	   bitsPerPixel, 
	   RasterByteOrder.Bgr, 
	   RasterViewPerspective.TopLeft, 
	   null, 
	   data1, 
	   size); 
 
	// Get a pointer to the internal data and fill it with gray shades 
	long dataSize = image.DataSize; 
 
	byte[] buffer = new byte[dataSize]; 
	bool inc = true; 
	byte value = 0; 
	for (int i = 0; i < buffer.Length; i += 3) 
	{ 
		buffer[i + 0] = value; 
		buffer[i + 1] = value; 
		buffer[i + 2] = value; 
 
		if (inc) 
		{ 
			if (value == 255) 
			{ 
				inc = false; 
				value = 254; 
			} 
			else 
				value++; 
		} 
		else 
		{ 
			if (value == 0) 
			{ 
				inc = true; 
				value = 1; 
			} 
			else 
				value--; 
		} 
	} 
 
	// Copy this buffer to the image data 
	IntPtr data2 = (IntPtr)image.Data; 
	Marshal.Copy(buffer, 0, data2, buffer.Length); 
 
	// Save the image 
	codecs.Save(image, destFileName, RasterImageFormat.Bmp, 24); 
 
	image.Dispose(); 
	Marshal.FreeHGlobal(data1); 
	codecs.Dispose(); 
} 
 
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.