Leadtools Send comments on this topic. | Back to Introduction - All Topics | Help Version 16.5.9.25
RasterBufferResize Class
See Also  Members   Example 
Leadtools Namespace : RasterBufferResize Class



Provides support for resizing image data buffers.

Syntax

Visual Basic (Declaration) 
Public Class RasterBufferResize 
Visual Basic (Usage)Copy Code
Dim instance As RasterBufferResize
C# 
public class RasterBufferResize 
C++/CLI 
public ref class RasterBufferResize 

Example

This example will load an image, resizes each line then saves the resized image back to disk.

Visual BasicCopy Code
Public Sub RasterBufferResizeExample()
 RasterCodecs.Startup()
 Dim codecs As RasterCodecs = New RasterCodecs()
 codecs.ThrowExceptionsOnInvalidImages = True

 Dim srcFileName As String = LeadtoolsExamples.Common.ImagesPath.Path + "Image1.cmp"
 Dim destFileName As String = LeadtoolsExamples.Common.ImagesPath.Path + "Image1_resized.bmp"

 ' Load the source image
 Dim srcImage As RasterImage = codecs.Load(srcFileName)

 Dim destWidth As Integer = srcImage.Width \ 2
 Dim destHeight As Integer = srcImage.Height \ 2

 ' Create the destination image
 Dim destImage As RasterImage = 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
 Dim scanLine As Byte() = New Byte(srcImage.BytesPerLine - 1) {}

 ' resize it
 Dim bufferResize As RasterBufferResize = New RasterBufferResize()

 ' Initialize the resize process.
 bufferResize.Start(srcImage.Width, srcImage.Height, destImage.Width, destImage.Height)

 srcImage.Access()
 destImage.Access()

 ' Current destination row number
 Dim destRow As Integer = 0
 Dim i As Integer = 0
 Do While i < srcImage.Height
    ' 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
    Dim j As Integer = 0
    Do While j < bufferResize.CopyRepetitions
       destImage.SetRow(destRow, scanLine, 0, bufferResize.LineWidth * 3)
       destRow += 1
       j += 1
    Loop
    i += 1
 Loop

 destImage.Release()
 srcImage.Release()

 bufferResize.Stop()

 ' Save the destination image
 codecs.Save(destImage, destFileName, RasterImageFormat.Bmp, 24)

 ' Clean up
 srcImage.Dispose()
 destImage.Dispose()
 RasterCodecs.Shutdown()
      End Sub
C#Copy Code
public void RasterBufferResizeExample() 

   RasterCodecs.Startup(); 
   RasterCodecs codecs = new RasterCodecs(); 
   codecs.ThrowExceptionsOnInvalidImages = true; 
 
   string srcFileName = LeadtoolsExamples.Common.ImagesPath.Path + "Image1.cmp"; 
   string destFileName = LeadtoolsExamples.Common.ImagesPath.Path + "Image1_resized.bmp"; 
 
   // Load the source image 
   RasterImage srcImage = codecs.Load(srcFileName); 
 
   int destWidth = srcImage.Width / 2; 
   int destHeight = srcImage.Height / 2; 
 
   // Create the destination image 
   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); 
 
   // Clean up 
   srcImage.Dispose(); 
   destImage.Dispose(); 
   RasterCodecs.Shutdown(); 
}

Inheritance Hierarchy

System.Object
   Leadtools.RasterBufferResize

Requirements

Target Platforms: Microsoft .NET Framework 3.0, Windows XP, Windows Server 2003 family, Windows Server 2008 family

See Also