←Select platform

SetOverlayImage Method

Summary
Sets the overlay image for a certain index.
Syntax
C#
Objective-C
C++/CLI
Java
Python
public void SetOverlayImage( 
   int index, 
   RasterImage overlayImage, 
   RasterGetSetOverlayImageMode mode 
) 
- (BOOL)setOverlay:(nullable LTRasterImage *)overlayImage  
   forImageAtIndex:(NSInteger)index  
              mode:(LTRasterGetSetOverlayImageMode)mode  
             error:(NSError **)error 
public void setOverlayImage( 
  int index,  
  RasterImage overlayImage,  
  RasterGetSetOverlayImageMode mode 
) 
public: 
void SetOverlayImage(  
   int index, 
   RasterImage^ overlayImage, 
   RasterGetSetOverlayImageMode mode 
)  
def SetOverlayImage(self,mode): 

Parameters

index
The index of the overlay for which to set the image. This index is zero-based and should be less than or equal to MaxOverlays.

overlayImage
The new overlay image. This can be null, in which case the corresponding overlay image will be freed.

mode
Determines how to insert the image, possible values are:

Mode Description
RasterGetSetOverlayImageMode.Copy A copy of overlayImage is inserted in the overlay list.
RasterGetSetOverlayImageMode.NoCopy overlayImage is set into the overlay list without making a copy. You should be careful when modifying overlayImage because you can modify/invalidate the entry in the overlay image list.
RasterGetSetOverlayImageMode.Move overlayImage is moved into the overlay list. It will also be disposed, so you cannot make changes to it. This is recommended over RasterGetSetOverlayImageMode.NoCopy.
Remarks

This method is available in the (Document/Medical only) Toolkits.

Calling this method with a valid image set in  overlayImage frees the old overlay image at the specified index and sets the overlay image at the index to the new image referenced by  overlayImage.

If  overlayImage is null, the old overlay image is freed and the size is reset to:

OverlayWidth = Image.ImageWidth - OverlayImage.Origin.X OverlayHeight = Image.ImageHeight - OverlayImage.Origin.Y

If  mode is RasterGetSetOverlayImageMode.NoCopy and  overlayImage is not null (Nothing), the image is inserted as is into the overlay array. This means whenever you update the data from  overlayImage, the overlay image is changed too. Great care should be taken when using this flag because you can invalidate the overlay image stored in the array. For example, if you dispose the overlay image, the data pointed to by the overlay image from the internal array is also freed, but the array does not know that this has happened and thinks the data pointer is still valid. If the overlay image is accessed in some way, a crash will occur. A safer way of quickly setting the data is to use RasterGetSetOverlayImageMode.Move.

If  mode is RasterGetSetOverlayImageMode.Move, the data from the  overlayImage is copied into the overlay array and then the  overlayImage object is disposed. This means that you can do anything with the  overlayImage object and the overlay image stored in the array will be unaffected. This is the most efficient way of setting the overlay image, because no copy will take place. overlayImage must reference an image that is 1-bit, overwise, this method will throw an exception.

For more information, refer to Overlay Overview.

Example
C#
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Core; 
using Leadtools.ImageProcessing.Color; 
using Leadtools.Dicom; 
using Leadtools.Drawing; 
using Leadtools.Controls; 
using Leadtools.Svg; 
 
 
public void GetOverlayImageExample() 
{ 
   RasterCodecs codecs = new RasterCodecs(); 
   // load an image and set an overlay 
   RasterImage image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "DICOM", "image2.dcm"), 0, CodecsLoadByteOrder.BgrOrGray, 1, 1); 
   RasterImage imageOverlay1 = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "ulay1.bmp"), 1, CodecsLoadByteOrder.Rgb, 1, 1); 
   RasterImage imageOverlay2 = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "ulay1.bmp"), 1, CodecsLoadByteOrder.Rgb, 1, 1); 
   image.SetOverlayImage(0, imageOverlay1, RasterGetSetOverlayImageMode.Copy); 
   image.SetOverlayImage(1, imageOverlay2, RasterGetSetOverlayImageMode.Copy); 
 
   // update the attributes of one of the overlays 
   RasterOverlayAttributes attributes = image.GetOverlayAttributes(0, 
      RasterGetSetOverlayAttributesFlags.Color | 
      RasterGetSetOverlayAttributesFlags.Flags | 
      RasterGetSetOverlayAttributesFlags.Origin | 
      RasterGetSetOverlayAttributesFlags.BitIndex); 
 
   attributes.Color = new RasterColor(255, 255, 255); 
   attributes.AutoPaint = true; 
   attributes.AutoProcess = true; 
   attributes.Origin = new LeadPoint(5, 5); 
   attributes.BitPosition = image.BitsPerPixel - 1; 
 
   image.UpdateOverlayAttributes( 
      0, 
      attributes, 
      RasterGetSetOverlayAttributesFlags.Color | 
      RasterGetSetOverlayAttributesFlags.Flags | 
      RasterGetSetOverlayAttributesFlags.Origin | 
      RasterGetSetOverlayAttributesFlags.BitIndex); 
 
 
   int count = image.OverlayCount; 
   for (int i = 0; i < count; i++) 
   { 
      using (RasterImage overlayTest = image.GetOverlayImage(i, RasterGetSetOverlayImageMode.NoCopy)) 
      { 
         string fileName = string.Format(Path.Combine(LEAD_VARS.ImagesDir, "overlay{0}_copy.bmp"), i); 
         codecs.Save(overlayTest, fileName, RasterImageFormat.Bmp, 1); 
      } 
   } 
 
   image.Dispose(); 
   imageOverlay1.Dispose(); 
   imageOverlay2.Dispose(); 
   codecs.Dispose(); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
Requirements

Target Platforms

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

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