Is this page helpful?
public static class RasterImagePainter
The LEADTOOLS RasterImage class provides platform independent representation of an image. It serves as a working area for image manipulation and conversion. LEADTOOLS functions use this class for accessing the image in memory and for maintaining the characteristics of the image. This topic discusses how to use the LEADTOOLS RasterImage class with the Windows GDI and GDI+ (System.Drawing) platforms.
For more information refer to RasterImage and GDI/GDI+.
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Drawing;
using Leadtools.ImageProcessing;
public void PaintExample()
{
PaintForm f = new PaintForm();
f.ShowDialog();
}
class PaintForm : Form
{
private RasterImage image;
private RasterPaintProperties props;
public PaintForm()
{
// Load the image
RasterCodecs codecs = new RasterCodecs();
string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif");
image = codecs.Load(srcFileName);
Text = "Normal - doubleclick to change.";
props = RasterPaintProperties.Default;
props.PaintDisplayMode = RasterPaintDisplayModeFlags.None;
}
protected override void Dispose(bool disposing)
{
// Clean up
if (disposing)
{
image.Dispose();
}
base.Dispose(disposing);
}
protected override void OnDoubleClick(EventArgs e)
{
if ((props.PaintDisplayMode & RasterPaintDisplayModeFlags.ScaleToGray) == RasterPaintDisplayModeFlags.ScaleToGray)
{
Text = "Normal - doubleclick to change.";
props.PaintDisplayMode &= ~RasterPaintDisplayModeFlags.ScaleToGray;
}
else
{
Text = "ScaleToGray - doubleclick to change.";
props.PaintDisplayMode |= RasterPaintDisplayModeFlags.ScaleToGray;
}
Invalidate();
base.OnDoubleClick(e);
}
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);
base.OnPaint(e);
}
}
static class LEAD_VARS
{
public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images";
}