←Select platform

RasterBufferConverter Class

Summary
Provides support for converting image data buffers.
Syntax
C#
Objective-C
C++/CLI
Python
public static class RasterBufferConverter 
@interface LTRasterBufferConverter : NSObject 
public ref class RasterBufferConverter abstract sealed  
class RasterBufferConverter: 
Example

This example loads an image at 24 bits per pixel, and creates a new image at 16 bits per pixel, and uses the Convert method to convert data from 24 bits per pixel to 16 bits per pixel.

C#
using Leadtools; 
using Leadtools.Codecs; 
 
 
public void RasterBufferConverterExample() 
{ 
	string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp"); 
	string destFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1_16bits.bmp"); 
 
	using (RasterCodecs codecs = new RasterCodecs()) 
	{ 
		codecs.ThrowExceptionsOnInvalidImages = true; 
 
		// Load the image, at 24 bit per pixel. 
		using (RasterImage srcImage = codecs.Load(srcFileName, 24, CodecsLoadByteOrder.Bgr, 1, 1)) 
		{ 
			Assert.IsNotNull(srcImage); 
			Assert.IsTrue(srcImage.BitsPerPixel == 24); 
 
			// Create a new 16-bit image. 
			using (RasterImage destImage = new RasterImage( 
			   RasterMemoryFlags.Conventional, 
			   srcImage.Width, 
			   srcImage.Height, 
			   16, 
			   srcImage.Order, 
			   srcImage.ViewPerspective, 
			   srcImage.GetPalette(), 
			   IntPtr.Zero, 
			   0)) 
			{ 
 
				Assert.IsNotNull(destImage); 
				Assert.IsTrue(destImage.BitsPerPixel == 16); 
 
				// Create a buffer large enough to hold a source or destination row 
				int bytesPerLine = Math.Max(srcImage.BytesPerLine, destImage.BytesPerLine); 
				byte[] buffer = new byte[bytesPerLine]; 
 
				// Process each row from src to dest image 
				srcImage.Access(); 
				destImage.Access(); 
 
				for (int i = 0; i < srcImage.Height; i++) 
				{ 
					srcImage.GetRow(i, buffer, 0, srcImage.BytesPerLine); 
 
					RasterBufferConverter.Convert( 
					   buffer, 
					   0, 
					   srcImage.Width, 
					   srcImage.BitsPerPixel, 
					   destImage.BitsPerPixel, 
					   srcImage.Order, 
					   destImage.Order, 
					   null, 
					   null, 
					   0); 
 
					destImage.SetRow(i, buffer, 0, destImage.BytesPerLine); 
				} 
 
				destImage.Release(); 
				srcImage.Release(); 
 
				// Save the destination image back to disk 
				codecs.Save(destImage, destFileName, RasterImageFormat.Bmp, 16); 
			} 
		} 
	} 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
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.