Public Sub RasterImageResizeExample()
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_RasterImageResize.bmp"
Dim srcImage As RasterImage = codecs.Load(srcFileName)
Dim resize As RasterImageResize = New RasterImageResize()
AddHandler resize.Resize, AddressOf resize_Resize
Dim destWidth As Integer = srcImage.Width \ 2
Dim destHeight As Integer = srcImage.Height \ 2
resize.Start(srcImage, destWidth, destHeight, srcImage.BitsPerPixel, srcImage.Order, srcImage.DitheringMethod, RasterSizeFlags.None, srcImage.GetPalette())
Dim destImage As RasterImage = New RasterImage(RasterMemoryFlags.Conventional, destWidth, destHeight, srcImage.BitsPerPixel, srcImage.Order, srcImage.ViewPerspective, srcImage.GetPalette(), IntPtr.Zero, 0)
Dim buffer As Byte() = New Byte(destImage.BytesPerLine - 1) {}
Dim row As Integer = 0
Do While row < destImage.Height
resize.ResizeBuffer(row, 0, buffer, 0, destImage.BytesPerLine)
destImage.SetRow(row, buffer, 0, destImage.BytesPerLine)
row += 1
Loop
resize.Stop()
codecs.Save(destImage, destFileName, RasterImageFormat.Bmp, 24)
srcImage.Dispose()
destImage.Dispose()
RasterCodecs.Shutdown()
End Sub
Private Sub resize_Resize(ByVal sender As Object, ByVal e As RasterImageResizeEventArgs)
If e.Row >= e.Image.Height Then
e.Cancel = True
Return
End If
Dim buffer As Byte() = New Byte(e.Bytes - 1) {}
e.Image.Access()
e.Image.GetRowColumn(e.Row, e.Column, buffer, 0, e.Bytes)
e.Image.Release()
Marshal.Copy(buffer, 0, e.Buffer, e.Bytes)
Console.WriteLine("{0}, {1}", e.Row, e.Column)
End Sub |