←Select platform

RasterPaintEngine Enumeration

Summary
Indicates the painting engine to use when rendering images using the Windows GDI or GDI+ engines..
Syntax
C#
C++/CLI
Python
public enum RasterPaintEngine   
public enum class RasterPaintEngine   
class RasterPaintEngine(Enum): 
   Gdi = 0 
   GdiPlus = 1 
Members
ValueMemberDescription
0Gdi Use Windows GDI when painting Leadtools.RasterImage objects
1GdiPlus Use Windows GDI+ when painting Leadtools.RasterImage objects
Remarks

When the RasterPaintEngine.Gdi engine is used, the RasterImagePainter.Paint method internally will call the Win32 API functions to paint the image.

When the RasterPaintEngine.GdiPlus engine is used, the RasterImagePainter.Paint method internally will call GDI+ Graphics.DrawImage methods to paint the image. Note that if the Leadtools.RasterImage object is not fully compatible with GDI+, the framework will internally make a copy of parts of the image data (bands) and paints them to the destination device. The original data is not converted and no changes will be made to the original image.

Choosing a paint engine depends on the Leadtools.RasterImage object and your specific needs:

  • RasterPaintEngine.Gdi is generally faster than RasterPaintEngine.GdiPlus since painting in Windows is faster using the Windows GDI is faster than using GDI+.
  • If you need to use GDI+ specific features (for example, if the Leadtools.RasterImage has a transparent color or is a 32-bit image with an alpha channel), then use RasterPaintEngine.GdiPlus. RasterPaintEngine.Gdi does not support transparency nor painting the alpha channel values of an image.
Example
C#
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Drawing; 
 
 
public void RasterPaintPropertiesExample() 
{ 
   // Create the form  
   PaintPropertiesForm f = new PaintPropertiesForm(); 
   f.ShowDialog(); 
} 
 
class PaintPropertiesForm : Form 
{ 
   private int index = 0; 
   private RasterImage rasterImage; 
   private RasterPaintProperties paintProperties; 
 
   public PaintPropertiesForm() 
   { 
      Text = "GDI paint engine - normal - Double click to show next RasterPaintProperties options"; 
      SetStyle(ControlStyles.ResizeRedraw, true); 
      SetStyle(ControlStyles.AllPaintingInWmPaint, true); 
      SetStyle(ControlStyles.OptimizedDoubleBuffer, true); 
      SetStyle(ControlStyles.UserPaint, true); 
 
      // Load an image  
      string fileName = Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif"); 
 
      using (RasterCodecs codecs = new RasterCodecs()) 
      { 
         codecs.ThrowExceptionsOnInvalidImages = true; 
         rasterImage = codecs.Load(fileName); 
      } 
 
      paintProperties = RasterPaintProperties.Default; 
 
      // Start with GDI paint engine and normal paint scaling 
      paintProperties.PaintEngine = RasterPaintEngine.Gdi; 
      paintProperties.PaintDisplayMode = RasterPaintDisplayModeFlags.None; 
   } 
 
   protected override void Dispose(bool disposing) 
   { 
      if (disposing) 
      { 
         if (rasterImage != null) 
            rasterImage.Dispose(); 
      } 
 
      base.Dispose(disposing); 
   } 
 
   protected override void OnDoubleClick(EventArgs e) 
   { 
      switch (index) 
      { 
         case 0: 
            Text = "GDI paint engine - SourceAnd ROP - Double click to show next RasterPaintProperties options"; 
            paintProperties.RasterOperation = RasterPaintProperties.SourceAnd; 
            break; 
 
         case 1: 
            Text = "GDI paint engine - Scale to gray - Double click to show next RasterPaintProperties options"; 
            paintProperties.RasterOperation = RasterPaintProperties.SourceCopy; 
            paintProperties.PaintDisplayMode = RasterPaintDisplayModeFlags.ScaleToGray; 
            break; 
 
         case 2: 
            Text = "GDI+ paint engine - Double click to set the opacity"; 
            paintProperties.PaintEngine = RasterPaintEngine.GdiPlus; 
            break; 
 
         case 3: 
            Text = "GDI+ paint engine - Opacity set to 50% - Done"; 
            paintProperties.Opacity = 128; 
            break; 
 
         default: 
            break; 
      } 
 
      index++; 
      Invalidate(); 
      base.OnDoubleClick(e); 
   } 
 
   protected override void OnPaint(PaintEventArgs e) 
   { 
      // Paint the image  
      LeadRect destRect = LeadRect.FromLTRB(ClientRectangle.Left, ClientRectangle.Top, ClientRectangle.Right, ClientRectangle.Bottom); 
      destRect = RasterImage.CalculatePaintModeRectangle( 
         rasterImage.ImageWidth, 
         rasterImage.ImageHeight, 
         destRect, 
         RasterPaintSizeMode.Fit, 
         RasterPaintAlignMode.Center, 
         RasterPaintAlignMode.Center); 
 
      RasterImagePainter.Paint(rasterImage, e.Graphics, destRect, paintProperties); 
 
      base.OnPaint(e); 
   } 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images"; 
} 
Requirements

Target Platforms

See Also

Reference

Leadtools.Drawing Namespace

Help Version 22.0.2023.3.31
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Drawing Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.