using Leadtools;
using Leadtools.Codecs;
using Leadtools.Drawing;
using Leadtools.ImageProcessing;
public void PaintOverlayExample()
{
PaintOverlayForm f = new PaintOverlayForm();
f.ShowDialog();
}
class PaintOverlayForm : Form
{
private RasterImage image;
private RasterPaintProperties props;
public PaintOverlayForm()
{
// Load the image
RasterCodecs codecs = new RasterCodecs();
image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir,"DICOM", "Image2.dcm"));
using (RasterImage overlay = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif")))
{
ResizeCommand cmd = new ResizeCommand();
using (RasterImage destImage = new RasterImage(RasterMemoryFlags.Conventional, image.Width, image.Height, 1, RasterByteOrder.Bgr, image.ViewPerspective, null, IntPtr.Zero, 0))
{
cmd.Flags = RasterSizeFlags.FavorBlack;
cmd.DestinationImage = destImage;
cmd.Run(overlay);
image.SetOverlayImage(0, destImage, RasterGetSetOverlayImageMode.Copy);
}
}
RasterOverlayAttributes attributes = image.GetOverlayAttributes(0,
RasterGetSetOverlayAttributesFlags.Color |
RasterGetSetOverlayAttributesFlags.Flags |
RasterGetSetOverlayAttributesFlags.Origin |
RasterGetSetOverlayAttributesFlags.BitIndex);
attributes.AutoPaint = false;
attributes.Color = new RasterColor(255, 0, 0);
image.UpdateOverlayAttributes(
0,
attributes,
RasterGetSetOverlayAttributesFlags.Color |
RasterGetSetOverlayAttributesFlags.Flags |
RasterGetSetOverlayAttributesFlags.Origin |
RasterGetSetOverlayAttributesFlags.BitIndex);
Text = "PaintOverlay Example";
props = RasterPaintProperties.Default;
props.UsePaintPalette = true;
}
protected override void Dispose(bool disposing)
{
// Clean up
if (disposing)
{
image.Dispose();
}
base.Dispose(disposing);
}
protected override void OnPaint(PaintEventArgs e)
{
// Draw the image fit and center on this form
LeadRect destRect = LeadRect.FromLTRB(ClientRectangle.Left, ClientRectangle.Top, ClientRectangle.Right, ClientRectangle.Bottom);
destRect = RasterImage.CalculatePaintModeRectangle(
image.ImageWidth,
image.ImageHeight,
destRect,
RasterPaintSizeMode.Fit,
RasterPaintAlignMode.Center,
RasterPaintAlignMode.Center);
RasterImagePainter.Paint(image, e.Graphics, LeadRect.Empty, destRect, props);
RasterImagePainter.PaintOverlay(image, e.Graphics, 0, LeadRect.Empty, LeadRect.Empty, destRect, LeadRect.Empty, props);
base.OnPaint(e);
}
}
static class LEAD_VARS
{
public const string ImagesDir = @"C:\LEADTOOLS21\Resources\Images";
}
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.Drawing
Imports Leadtools.ImageProcessing
Public Sub PaintOverlayExample()
Dim f As New PaintOverlayForm()
f.ShowDialog()
End Sub
Class PaintOverlayForm
Inherits Form
Private image As RasterImage
Private props As RasterPaintProperties
Public Sub New()
' Load the image
Dim codecs As New RasterCodecs()
image = codecs.Load(LeadtoolsExamples.Common.ImagesPath.Path + "Image2.dcm")
Using overlay As RasterImage = codecs.Load(LeadtoolsExamples.Common.ImagesPath.Path + "Ocr1.tif")
Dim cmd As New ResizeCommand()
Using destImage As New RasterImage(RasterMemoryFlags.Conventional, image.Width, image.Height, 1, RasterByteOrder.Bgr, image.ViewPerspective, Nothing, IntPtr.Zero, 0)
cmd.Flags = RasterSizeFlags.FavorBlack
cmd.DestinationImage = destImage
cmd.Run(overlay)
image.SetOverlayImage(0, destImage, RasterGetSetOverlayImageMode.Copy)
End Using
End Using
Dim attributes As RasterOverlayAttributes = image.GetOverlayAttributes(0,
RasterGetSetOverlayAttributesFlags.Color Or
RasterGetSetOverlayAttributesFlags.Flags Or
RasterGetSetOverlayAttributesFlags.Origin Or
RasterGetSetOverlayAttributesFlags.BitIndex)
attributes.AutoPaint = False
attributes.Color = New RasterColor(255, 0, 0)
image.UpdateOverlayAttributes(
0,
attributes,
RasterGetSetOverlayAttributesFlags.Color Or
RasterGetSetOverlayAttributesFlags.Flags Or
RasterGetSetOverlayAttributesFlags.Origin Or
RasterGetSetOverlayAttributesFlags.BitIndex)
Text = "PaintOverlay Example"
props = RasterPaintProperties.Default
props.UsePaintPalette = True
End Sub
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
' Clean up
If disposing Then
image.Dispose()
End If
MyBase.Dispose(disposing)
End Sub
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
' Draw the image fit and center on this form
Dim destRect As LeadRect = LeadRect.FromLTRB(ClientRectangle.Left, ClientRectangle.Top, ClientRectangle.Right, ClientRectangle.Bottom)
destRect = RasterImage.CalculatePaintModeRectangle(
image.ImageWidth,
image.ImageHeight,
destRect,
RasterPaintSizeMode.Fit,
RasterPaintAlignMode.Center,
RasterPaintAlignMode.Center)
RasterImagePainter.Paint(image, e.Graphics, LeadRect.Empty, destRect, props)
RasterImagePainter.PaintOverlay(image, e.Graphics, 0, LeadRect.Empty, LeadRect.Empty, destRect, LeadRect.Empty, props)
MyBase.OnPaint(e)
End Sub
End Class