←Select platform

RasterImage Constructor(RasterImage)

Summary

Constructs a new RasterImage from the specified existing RasterImage object.

Syntax

C#
VB
Java
Objective-C
WinRT C#
C++
Public Function New( _ 
   ByVal srcImage As Leadtools.RasterImage _ 
) 
public RasterImage(  
   Leadtools.RasterImage srcImage 
) 
- (nullable instancetype)initWithImage:(LTRasterImage *)rasterImage error:(NSError **)error 
public RasterImage(RasterImage srcImage) 
function RasterImage(  
   srcImage  
) 
public: 
RasterImage(  
   Leadtools.RasterImage^ srcImage 
) 

Parameters

srcImage
The RasterImage from which to create the new RasterImage.

Remarks

This constructor will "pull" all the internal data (image pages, metadata, etc) from srcImage and puts a copy of them into the newly created RasterImage.

After calling this constructor, srcImage remains valid and changes to its properties or data will not affect the newly created RasterImage object.

This constructor is useful when deriving your own classes from RasterImage as shown in the example below.

For more information, refer to Grayscale Images.

Example

This example derives a new class from then use the RasterImage(RasterImage) constructor.

C#
VB
Silverlight C#
Silverlight VB
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 LeadtoolsExamples.Common; 
using Leadtools.Svg; 
 
// A class that derives from RasterImage 
public class MyRasterImage : RasterImage 
{ 
   private int _myData; 
 
   public MyRasterImage(RasterImage src) 
      : 
      base(src) 
   { 
      _myData = 0; 
   } 
 
   public int MyData 
   { 
      get 
      { 
         return _myData; 
      } 
      set 
      { 
         _myData = value; 
      } 
   } 
} 
 
public void DerivedRasterImage() 
{ 
   RasterCodecs codecs = new RasterCodecs(); 
 
   string srcFileName = Path.Combine(ImagesPath.Path, "Image1.cmp"); 
 
   // Load the image 
   RasterImage img = codecs.Load(srcFileName); 
 
   // create a new MyRasterImage instance out of this image 
   MyRasterImage myImage = new MyRasterImage(img); 
 
   // img is inavlid now and shoule be disposed 
   img.Dispose(); 
 
   // Now you can use myImage just like any other RasterImage but with your own data 
   myImage.PaintGamma = 50;   // RasterImage property 
   myImage.MyData = 10;       // MyRasterImage property 
 
   Assert.IsTrue(myImage.PaintGamma == 50); 
   Assert.IsTrue(myImage.MyData == 10); 
 
   // Clean up 
   myImage.Dispose(); 
   codecs.Dispose(); 
} 
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.ImageProcessing 
Imports Leadtools.ImageProcessing.Core 
Imports Leadtools.ImageProcessing.Color 
Imports Leadtools.Controls 
Imports Leadtools.Dicom 
Imports Leadtools.Drawing 
Imports Leadtools.Svg 
 
' A class that derives from RasterImage 
Public Class MyRasterImage : Inherits RasterImage 
   Private _myData As Integer 
 
   Public Sub New(ByVal src As RasterImage) 
 
      MyBase.New(src) 
      _myData = 0 
   End Sub 
 
   Public Property MyData() As Integer 
      Get 
         Return _myData 
      End Get 
      Set(ByVal value As Integer) 
         _myData = value 
      End Set 
   End Property 
End Class 
 
Public Sub DerivedRasterImage() 
   Dim codecs As RasterCodecs = New RasterCodecs() 
 
   Dim srcFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp") 
 
   ' Load the image 
   Dim img As RasterImage = codecs.Load(srcFileName) 
 
   ' create a new MyRasterImage instance out of this image 
   Dim myImage As MyRasterImage = New MyRasterImage(img) 
 
   ' img is inavlid now and shoule be disposed 
   img.Dispose() 
 
   ' Now you can use myImage just like any other RasterImage but with your own data 
   myImage.PaintGamma = 50 ' RasterImage property 
   myImage.MyData = 10 ' MyRasterImage property 
 
   Debug.Assert(myImage.PaintGamma = 50) 
   Debug.Assert(myImage.MyData = 10) 
 
   ' Clean up 
   myImage.Dispose() 
   codecs.Dispose() 
End Sub 
 
Public NotInheritable Class LEAD_VARS 
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" 
End Class 
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Dicom; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Core; 
using Leadtools.ImageProcessing.Color; 
using Leadtools.Examples; 
using Leadtools.Windows.Media; 
 
// A class that derives from RasterImage 
public class MyRasterImage : RasterImage 
{ 
   private int _myData; 
 
   public MyRasterImage(RasterImage src) 
      : 
      base(src) 
   { 
      _myData = 0; 
   } 
 
   public int MyData 
   { 
      get 
      { 
         return _myData; 
      } 
      set 
      { 
         _myData = value; 
      } 
   } 
} 
 
public void DerivedRasterImage(RasterImage srcImage) 
{ 
   // create a new MyRasterImage instance out of this image 
   MyRasterImage myImage = new MyRasterImage(srcImage); 
 
   // srcImage is inavlid now and should be disposed 
   srcImage.Dispose(); 
 
   // Now you can use myImage just like any other RasterImage but with your own data 
   myImage.TransparentColor = RasterColorConverter.FromColor(Colors.Blue);   // RasterImage property 
   myImage.MyData = 10;       // MyRasterImage property 
 
   Debug.Assert(myImage.MyData == 10); 
 
   // Clean up 
   myImage.Dispose(); 
} 
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.Dicom 
Imports Leadtools.ImageProcessing 
Imports Leadtools.ImageProcessing.Core 
Imports Leadtools.ImageProcessing.Color 
Imports Leadtools.Windows.Media 
 
' A class that derives from RasterImage 
Public Class MyRasterImage : Inherits RasterImage 
   Private _myData As Integer 
 
   Public Sub New(ByVal src As RasterImage) 
 
      MyBase.New(src) 
      _myData = 0 
   End Sub 
 
   Public Property MyData() As Integer 
      Get 
         Return _myData 
      End Get 
      Set 
         _myData = Value 
      End Set 
   End Property 
End Class 
 
Public Sub DerivedRasterImage(ByVal srcImage As RasterImage) 
   ' create a new MyRasterImage instance out of this image 
   Dim myImage As MyRasterImage = New MyRasterImage(srcImage) 
 
   ' srcImage is inavlid now and should be disposed 
   srcImage.Dispose() 
 
   ' Now you can use myImage just like any other RasterImage but with your own data 
   myImage.TransparentColor = RasterColorConverter.FromColor(Colors.Blue) ' RasterImage property 
   myImage.MyData = 10 ' MyRasterImage property 
 
   Debug.Assert(myImage.MyData = 10) 
 
   ' Clean up 
   myImage.Dispose() 
End Sub 

Requirements

Target Platforms

Help Version 19.0.2017.10.19
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.

Leadtools Assembly