←Select platform

RasterOperation Property

Summary
Gets or sets the ROP value.
Syntax
C#
C++/CLI
Python
public int RasterOperation { get; set; } 
public: 
property int RasterOperation { 
   int get(); 
   void set (    int ); 
} 
RasterOperation # get and set (RasterPaintProperties) 

Property Value

An integer value that represents the ROP value.

Remarks

Used only when PaintEngine is set to RasterPaintEngine.Gdi.

These codes define how the color data for the image is to be combined with the color data for the destination System.Drawing.Graphics to achieve the final color.

The following list shows some common raster operation codes:

Value Description
SourceCopy Copies the source rectangle directly to the destination rectangle
SourcePaint Combines the colors of the source and destination rectangles by using the Boolean OR operator
SourceAnd Combines the colors of the source and destination rectangles by using the Boolean AND operator
SourceInvert Combines the colors of the source and destination rectangles by using the Boolean XOR operator
SourceErase Combines the inverted colors of the destination rectangle with the colors of the source rectangle by using the Boolean AND operator
NotSourceCopy Copies the inverted source rectangle to the destination
NotSourceErase Combines the colors of the source and destination rectangles by using the Boolean OR operator and then inverts the resultant color
MergeCopy Merges the colors of the source rectangle with the brush currently selected in hdcDest, by using the Boolean AND operator
MergePaint Merges the colors of the inverted source rectangle with the colors of the destination rectangle by using the Boolean OR operator
PatternCopy Copies the brush currently selected in hdcDest, into the destination bitmap
PatternPaint Combines the colors of the brush currently selected in hdcDest, with the colors of the inverted source rectangle by using the Boolean OR operator. The result of this operation is combined with the colors of the destination rectangle by using the Boolean OR operator
PatternInvert Combines the colors of the brush currently selected in hdcDest, with the colors of the destination rectangle by using the Boolean XOR operator
DestinationInvert Inverts the destination rectangle
Blackness Fills the destination rectangle using the color associated with index 0 in the physical palette. (This color is black for the default physical palette)
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:\LEADTOOLS23\Resources\Images"; 
} 
Requirements

Target Platforms

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

Leadtools.Drawing Assembly

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