Displays the contents of the RasterImageViewer in the given Graphics object.
public virtual void RedirectPaint(Graphics graphics,Rectangle src,Rectangle dest,Rectangle destClip,Matrix transform)
Public Overridable Sub RedirectPaint( _ByVal graphics As Graphics, _ByVal src As Rectangle, _ByVal dest As Rectangle, _ByVal destClip As Rectangle, _ByVal transform As Matrix _)
public:virtual void RedirectPaint(Graphics^ graphics,Rectangle src,Rectangle dest,Rectangle destClip,Matrix^ transform)
graphics
The Graphics object used to paint.
src
Rectangle which determines the portion of the image to paint.
dest
Rectangle which determines where the image is placed, and how it is scaled.
destClip
Rectangle which clips the image display.
transform
The matrix is used to transform from physical to logical coordinates
Use this function to paint the contents of the RasterImageViewer onto any System.Drawing.Graphics object. The contents of the RasterImageViewer includes the Image and anything painted in the PostImagePaint event handler. When using this function, pass either a valid transform or a dest rectangle, but NOT BOTH. It is an error to pass both a transform and a dest rectangle.
If you pass a transformmatrix, it is applied to the graphics object before any painting takes place. If you pass a dest rectangle, internally a transform is constructed from src and dest and it is applied to the graphics object before any painting takes place. Passing Rectangle.Empty for the src rectangle gives the default, which is equivalent to the size of the Image. Passing Rectangle.Empty for the destClip rectangle is equivalent to passing same System.Drawing.Rectangle as dst. Passing null for the transform argument means that src and dest are used to create a transform.
This example creates a Form with a RasterImageViewer and a panel. An image is loaded into the RasterImageViewer, and stationary and moving text are drawn on top of the image. A mirror image of RasterImageViewer contents is then painted on the panel.
using Leadtools.WinForms;using Leadtools;using Leadtools.Codecs;using Leadtools.ImageProcessing.Color;using Leadtools.Drawing;class MyForm2 : Form{class MyPanel : Panel{protected override void OnPaintBackground(PaintEventArgs pe){// do nothing}}RasterImageViewer viewer;MyPanel panel;public MyForm2(string title){Text = title;Size = new Size(750, 450);// Create the raster viewerviewer = new RasterImageViewer();viewer.DoubleBuffer = true;viewer.Dock = DockStyle.Fill;// Load an image into the viewerRasterCodecs codecs = new RasterCodecs();viewer.Image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "Sample1.cmp"));codecs.Dispose();// Create the panelpanel = new MyPanel();panel.Parent = this;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();panel.Paint += new PaintEventHandler(panel_Paint);viewer.PostImagePaint += new PaintEventHandler(viewer_PostImagePaint);viewer.RedirectImagePaint += new EventHandler(viewer_RedirectImagePaint);}void viewer_RedirectImagePaint(object sender, EventArgs e){panel.Invalidate();}void panel_Paint(object sender, PaintEventArgs e){if (viewer.Image != null){int dx = viewer.Image.Width / 2;int dy = viewer.Image.Height / 2;Rectangle dest = viewer.SourceRectangle;// move center of image to originMatrix m1 = new Matrix(1, 0, 0, 1, -dx, -dy);// mirror the imageMatrix m2 = new Matrix(-1, 0, 0, 1, 0, 0);m1.Multiply(m2, MatrixOrder.Append);// move back to original locationMatrix m3 = new Matrix(1, 0, 0, 1, dx, dy);m1.Multiply(m3, MatrixOrder.Append);// scale image to fit on panelfloat scaleX = (float)panel.Width / (float)viewer.Image.Width;float scaleY = (float)panel.Height / (float)viewer.Image.Height;Matrix m4 = new Matrix(scaleX, 0, 0, scaleY, 0, 0);m1.Multiply(m4, MatrixOrder.Append);// display contents of RaserImageViewer on panelviewer.RedirectPaint(e.Graphics,Rectangle.Empty, //_viewer.SourceRectangle,Rectangle.Empty,Rectangle.Empty, //e.ClipRectangle,m1);}}private void viewer_PostImagePaint(object sender, PaintEventArgs e){Graphics graphics = e.Graphics;GraphicsState graphicsState = graphics.Save();Font 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();}}public void RasterImageViewer_RedirectPaint(string title){MyForm2 form = new MyForm2(title);form.ShowDialog();}static class LEAD_VARS{public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";}
Imports Leadtools.WinFormsImports LeadtoolsImports Leadtools.CodecsImports Leadtools.ImageProcessing.ColorImports Leadtools.DrawingPrivate Class MyForm2 : Inherits FormPrivate Class MyPanel : Inherits PanelProtected Overrides Sub OnPaintBackground(ByVal pe As PaintEventArgs)' do nothingEnd SubEnd ClassPrivate viewer As RasterImageViewerPrivate panel As MyPanelPublic Sub New(ByVal title As String)Text = titleSize = New Size(750, 450)' Create the raster viewerviewer = New RasterImageViewer()viewer.DoubleBuffer = Trueviewer.Dock = DockStyle.Fill' Load an image into the viewerDim codecs As RasterCodecs = New RasterCodecs()viewer.Image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "Sample1.cmp"))codecs.Dispose()' Create the panelpanel = New MyPanel()panel.Parent = Mepanel.Width = 400panel.Height = 400panel.Dock = DockStyle.Rightpanel.BackColor = Color.Beigepanel.BorderStyle = BorderStyle.Fixed3DControls.Add(panel)panel.BringToFront()Controls.Add(viewer)viewer.BringToFront()AddHandler panel.Paint, AddressOf panel_PaintAddHandler viewer.PostImagePaint, AddressOf viewer_PostImagePaintAddHandler viewer.RedirectImagePaint, AddressOf viewer_RedirectImagePaintEnd SubPrivate Sub viewer_RedirectImagePaint(ByVal sender As Object, ByVal e As EventArgs)panel.Invalidate()End SubPrivate Sub panel_Paint(ByVal sender As Object, ByVal e As PaintEventArgs)If Not viewer.Image Is Nothing ThenDim dx As Integer = viewer.Image.Width \ 2Dim dy As Integer = viewer.Image.Height \ 2Dim dest As Rectangle = viewer.SourceRectangle' move center of image to originDim m1 As Matrix = New Matrix(1, 0, 0, 1, -dx, -dy)' mirror the imageDim m2 As Matrix = New Matrix(-1, 0, 0, 1, 0, 0)m1.Multiply(m2, MatrixOrder.Append)' move back to original locationDim m3 As Matrix = New Matrix(1, 0, 0, 1, dx, dy)m1.Multiply(m3, MatrixOrder.Append)' scale image to fit on panelDim 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)' display contents of RaserImageViewer on panelviewer.RedirectPaint(e.Graphics, Rectangle.Empty, Rectangle.Empty, Rectangle.Empty, m1)End IfEnd SubPrivate Sub viewer_PostImagePaint(ByVal sender As Object, ByVal e As PaintEventArgs)Dim graphics As Graphics = e.GraphicsDim 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 SubEnd ClassPublic Sub RasterImageViewer_RedirectPaint(ByVal title As String)Dim form As MyForm2 = New MyForm2(title)form.ShowDialog()End SubPublic NotInheritable Class LEAD_VARSPublic Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"End Class
Raster .NET | C API | C++ Class Library | JavaScript HTML5
Document .NET | C API | C++ Class Library | JavaScript HTML5
Medical .NET | C API | C++ Class Library | JavaScript HTML5
Medical Web Viewer .NET
