LEADTOOLS GDI/GDI+ (Leadtools.Drawing assembly) Send comments on this topic. | Back to Introduction - All Topics | Help Version 17.0.3.29
RasterPaintProperties Structure
See Also  Members   Example



Controls the speed, quality, and style used when painting a Leadtools.RasterImage object using the Windows GDI or GDI+ engines.

Object Model

RasterPaintProperties StructureRasterPaintProperties Structure

Syntax

Visual Basic (Declaration) 
Public Structure RasterPaintProperties 
   Inherits System.ValueType
Visual Basic (Usage)Copy Code
Dim instance As RasterPaintProperties
C# 
public struct RasterPaintProperties : System.ValueType 
C++/CLI 
public value class RasterPaintProperties : public System.ValueType 

Example

This example creates a windows form with various controls to shows the different RasterPaintProperties options.

Visual BasicCopy Code
Public Sub RasterPaintPropertiesExample()
   ' Create the form 
   Dim form As New PaintPropertiesForm()
   form.ShowDialog()
End Sub

Class PaintPropertiesForm
   Inherits Form
   Private index As Integer = 0
   Private rasterImage As RasterImage
   Private paintProperties As RasterPaintProperties

   Public Sub New()
      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 
      Dim fileName As String = LeadtoolsExamples.Common.ImagesPath.Path + "Ocr1.tif"

      Using codecs As New RasterCodecs()
         codecs.ThrowExceptionsOnInvalidImages = True
         rasterImage = codecs.Load(fileName)
      End Using

      paintProperties = RasterPaintProperties.Default

      ' Start with GDI paint engine and normal paint scaling
      paintProperties.PaintEngine = RasterPaintEngine.Gdi
      paintProperties.PaintDisplayMode = RasterPaintDisplayModeFlags.None
   End Sub

   Protected Overrides Sub Dispose(ByVal disposing As Boolean)
      If disposing Then
         If Not IsNothing(rasterImage) Then
            rasterImage.Dispose()
         End If
      End If

      MyBase.Dispose(disposing)
   End Sub

   Protected Overrides Sub OnDoubleClick(ByVal e As EventArgs)
      Select index
         Case 0
            Text = "GDI paint engine - SourceAnd ROP - Double click to show next RasterPaintProperties options"
            paintProperties.RasterOperation = RasterPaintProperties.SourceAnd

         Case 1
            Text = "GDI paint engine - Scale to gray - Double click to show next RasterPaintProperties options"
            paintProperties.RasterOperation = RasterPaintProperties.SourceCopy
            paintProperties.PaintDisplayMode = RasterPaintDisplayModeFlags.ScaleToGray

         Case 2
            Text = "GDI+ paint engine - Double click to set the opacity"
            paintProperties.PaintEngine = RasterPaintEngine.GdiPlus

         Case 3
            Text = "GDI+ paint engine - Opacity set to 50% - Done"
            paintProperties.Opacity = 128
      End Select

      index = index + 1
      Invalidate()
      MyBase.OnDoubleClick(e)
   End Sub

   Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
      ' Paint the image 
      Dim destRect As LeadRect = 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)

      MyBase.OnPaint(e)
   End Sub
End Class
C#Copy Code
public void RasterPaintPropertiesExample()
   {
      // Create the form 
      PaintPropertiesForm form = new PaintPropertiesForm();
      form.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:\Users\Public\Documents\LEADTOOLS Images";
}

Remarks

The various RasterImagePainter.Paint method overloads requires an instance of RasterPaintProperties to be passed. The members of the of the RasterPaintProperties passed controls the speed, quality, and style used when painting.

Inheritance Hierarchy

System.Object
   System.ValueType
      Leadtools.Drawing.RasterPaintProperties

Requirements

Target Platforms: Silverlight 3.0, Windows XP, Windows Server 2003 family, Windows Server 2008 family, Windows Vista, Windows 7, MAC OS/X (Intel Only)

See Also