Products | Support | Email a link to this topic. | Send comments on this topic. | Back to Introduction - All Topics | Help Version 19.0.6.28
|
Leadtools Namespace : RasterBufferResize Class |
public class RasterBufferResize
'Declaration
Public Class RasterBufferResize
'Usage
Dim instance As RasterBufferResize
public sealed class RasterBufferResize
function Leadtools.RasterBufferResize()
public ref class RasterBufferResize
This example will load an image, resizes each line then saves the resized image back to disk.
Imports Leadtools Imports Leadtools.Codecs Public Sub RasterBufferResizeExample() Dim codecs As RasterCodecs = New RasterCodecs() codecs.ThrowExceptionsOnInvalidImages = True Dim srcFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp") Dim destFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "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() End Sub Public NotInheritable Class LEAD_VARS Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" End Class
using Leadtools; using Leadtools.Codecs; public void RasterBufferResizeExample() { string srcFileName = Path.Combine(ImagesPath.Path, "Image1.cmp"); string destFileName = Path.Combine(ImagesPath.Path, "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); } } } }
using Leadtools; using Leadtools.Codecs; public async Task RasterBufferResizeExample() { RasterCodecs codecs = new RasterCodecs(); codecs.ThrowExceptionsOnInvalidImages = true; string srcFileName = @"Assets\Image1.cmp"; string destFileName = @"Image1_resized.bmp"; // Load the source image StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName); ILeadStream loadStream = LeadStreamFactory.Create(loadFile); RasterImage srcImage = await codecs.LoadAsync(loadStream, 24, CodecsLoadByteOrder.Bgr, 1, 1); Assert.IsTrue(srcImage.BitsPerPixel == 24); 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()); // allocate buffer for one scanline from source image Windows.Storage.Streams.Buffer scanLine = new Windows.Storage.Streams.Buffer((uint)srcImage.BytesPerLine); // resize it RasterBufferResize bufferResize = new RasterBufferResize(); // Initialize the resize process. bufferResize.Start(srcImage.Width, srcImage.Height, destImage.Width, destImage.Height); srcImage.AccessData(); destImage.AccessData(); // 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.ReleaseData(); srcImage.ReleaseData(); bufferResize.Stop(); // Save the destination image StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(destFileName); ILeadStream saveStream = LeadStreamFactory.Create(saveFile); await codecs.SaveAsync(destImage, saveStream, RasterImageFormat.Bmp, 24); // Clean up srcImage.Dispose(); destImage.Dispose(); }
using Leadtools; using Leadtools.Codecs; using Leadtools.Examples; public void RasterBufferResizeExample(RasterImage srcImage, Stream destStream) { RasterCodecs codecs = new RasterCodecs(); codecs.ThrowExceptionsOnInvalidImages = true; 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(), null, 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, destStream, RasterImageFormat.Bmp, 24); // Clean up srcImage.Dispose(); destImage.Dispose(); }
Imports Leadtools Imports Leadtools.Codecs Public Sub RasterBufferResizeExample(ByVal srcImage As RasterImage, ByVal destStream As Stream) Dim codecs As RasterCodecs = New RasterCodecs() codecs.ThrowExceptionsOnInvalidImages = True 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(), Nothing, 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, destStream, RasterImageFormat.Bmp, 24) ' Clean up srcImage.Dispose() destImage.Dispose() End Sub