Private Class MyForm2 : Inherits Form
Private Class MyPanel : Inherits Panel
Protected Overrides Sub OnPaintBackground(ByVal pe As PaintEventArgs)
End Sub
End Class
Private viewer As RasterImageViewer
Private panel As MyPanel
Public Sub New(ByVal title As String)
Text = title
Size = New Size(750, 450)
viewer = New RasterImageViewer()
viewer.DoubleBuffer = True
viewer.Dock = DockStyle.Fill
RasterCodecs.Startup()
Dim codecs As RasterCodecs = New RasterCodecs()
viewer.Image = codecs.Load("C:\Program Files\LEAD Technologies\LEADTOOLS 15\Images\Sample1.cmp")
codecs.Dispose()
RasterCodecs.Shutdown()
panel = New MyPanel()
panel.Parent = Me
panel.Width = 400
panel.Height = 400
panel.Dock = DockStyle.Right
panel.BackColor = Color.Beige
panel.BorderStyle = BorderStyle.Fixed3D
Controls.Add(panel)
panel.BringToFront()
Controls.Add(viewer)
viewer.BringToFront()
AddHandler panel.Paint, AddressOf panel_Paint
AddHandler viewer.PostImagePaint, AddressOf viewer_PostImagePaint
AddHandler viewer.RedirectImagePaint, AddressOf viewer_RedirectImagePaint
End Sub
Private Sub viewer_RedirectImagePaint(ByVal sender As Object, ByVal e As EventArgs)
panel.Invalidate()
End Sub
Private Sub panel_Paint(ByVal sender As Object, ByVal e As PaintEventArgs)
If Not viewer.Image Is Nothing Then
Dim dx As Integer = viewer.Image.Width \ 2
Dim dy As Integer = viewer.Image.Height \ 2
Dim dest As Rectangle = viewer.SourceRectangle
Dim m1 As Matrix = New Matrix(1, 0, 0, 1, -dx, -dy)
Dim m2 As Matrix = New Matrix(-1, 0, 0, 1, 0, 0)
m1.Multiply(m2, MatrixOrder.Append)
Dim m3 As Matrix = New Matrix(1, 0, 0, 1, dx, dy)
m1.Multiply(m3, MatrixOrder.Append)
Dim scaleX As Single = CSng(panel.Width) / CSng(viewer.Image.Width)
Dim scaleY As Single = CSng(panel.Height) / CSng(viewer.Image.Height)
Dim m4 As Matrix = New Matrix(scaleX, 0, 0, scaleY, 0, 0)
m1.Multiply(m4, MatrixOrder.Append)
viewer.RedirectPaint(e.Graphics, Rectangle.Empty, Rectangle.Empty, Rectangle.Empty, m1)
End If
End Sub
Private Sub viewer_PostImagePaint(ByVal sender As Object, ByVal e As PaintEventArgs)
Dim graphics As Graphics = e.Graphics
Dim graphicsState As GraphicsState = graphics.Save()
Dim font As Font = New Font("Arial", 16)
e.Graphics.DrawString("This text stays with the window", font, Brushes.Yellow, New PointF(100, 100))
graphics.MultiplyTransform(viewer.Transform)
e.Graphics.DrawString("This text stays with the image.", font, Brushes.White, New PointF(100, 200))
graphics.Restore(graphicsState)
graphics.Flush()
End Sub
End Class
Public Sub RasterImageViewer_RedirectPaint(ByVal title As String)
Dim form As MyForm2 = New MyForm2(title)
form.ShowDialog()
End Sub |