←Select platform

ResizeBuffer(IntPtr,int,int) Method

Summary
Resizes an unmanaged buffer to the new size specified with the Start method.
Syntax
C#
C++/CLI
Python
public void ResizeBuffer( 
   IntPtr buffer, 
   int row, 
   int bitsPerPixel 
) 
public: 
void ResizeBuffer(  
   IntPtr buffer, 
   int row, 
   int bitsPerPixel 
)  
def ResizeBuffer(self,buffer,row,bitsPerPixel): 

Parameters

buffer
The unmanaged buffer containing the original scanline to be resized.

row
Current row of the original bitmap.

bitsPerPixel
Bits per pixel, which is the same for the original and the resized bitmap.

Remarks buffer contains the buffer containing a line from the original image to be resized. Your code must allocate the buffer and copy the data into it before calling this method.

The same buffer holds the data before and after it is resized. Therefore, the buffer must be big enough to hold whichever is larger. (The original line is larger when reducing an image; the resulting line is larger when enlarging the image.)

Before calling this function, you must call the Start method.

When all lines have been processed, you must call the Stop method.

For more information, refer to Introduction to Image Processing With LEADTOOLS.

Example
C#
using Leadtools; 
using Leadtools.Codecs; 
 
 
public void RasterBufferResizeExample() 
{ 
	string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp"); 
	string destFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1_resized.bmp"); 
 
	using (RasterCodecs codecs = new RasterCodecs()) 
	{ 
		codecs.ThrowExceptionsOnInvalidImages = true; 
 
		// Load the source image 
		using (RasterImage srcImage = codecs.Load(srcFileName)) 
		{ 
			int destWidth = srcImage.Width / 2; 
			int destHeight = srcImage.Height / 2; 
 
			// Create the destination image 
			using (RasterImage destImage = new RasterImage( 
			   RasterMemoryFlags.Conventional, 
			   destWidth, 
			   destHeight, 
			   srcImage.BitsPerPixel, 
			   srcImage.Order, 
			   srcImage.ViewPerspective, 
			   srcImage.GetPalette(), 
			   IntPtr.Zero, 
			   0)) 
			{ 
 
				// allocate buffer for one scanline from source image 
				byte[] scanLine = new byte[srcImage.BytesPerLine]; 
 
				// resize it 
				RasterBufferResize bufferResize = new RasterBufferResize(); 
 
				// Initialize the resize process. 
				bufferResize.Start(srcImage.Width, srcImage.Height, destImage.Width, destImage.Height); 
 
				srcImage.Access(); 
				destImage.Access(); 
 
				// Current destination row number 
				int destRow = 0; 
				for (int i = 0; i < srcImage.Height; i++) 
				{ 
					// Get a scanline from the source image and resize it 
					srcImage.GetRow(i, scanLine, 0, srcImage.BytesPerLine); 
					bufferResize.ResizeBuffer(scanLine, 0, i, srcImage.BitsPerPixel); 
 
					// Output as many or as few rows as ResizeBuffer supplies 
					for (int j = 0; j < bufferResize.CopyRepetitions; j++) 
					{ 
						destImage.SetRow(destRow, scanLine, 0, bufferResize.LineWidth * 3); 
						destRow++; 
					} 
				} 
 
				destImage.Release(); 
				srcImage.Release(); 
 
				bufferResize.Stop(); 
 
				// Save the destination image 
				codecs.Save(destImage, destFileName, RasterImageFormat.Bmp, 24); 
			} 
		} 
	} 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
Requirements

Target Platforms

Help Version 23.0.2024.2.29
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.