←Select platform

RasterImage Constructor(RasterImage)

Summary
Constructs a new RasterImage from the specified existing RasterImage object.
Syntax
C#
Objective-C
C++/CLI
Java
Python
- (nullable instancetype)initWithImage:(LTRasterImage *)rasterImage error:(NSError **)error 
public RasterImage( 
   RasterImage srcImage 
); 
public: 
RasterImage(  
   RasterImage^ srcImage 
) 
__init__(self,srcImage) # Overloaded constructor 

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#
Java
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; 
 
 
// 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(LEAD_VARS.ImagesDir, "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(); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
 
import java.io.File; 
import java.io.FileInputStream; 
import java.io.IOException; 
import java.io.InputStream; 
import java.util.ArrayList; 
import java.util.List; 
 
import org.junit.*; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
import static org.junit.Assert.*; 
 
import leadtools.*; 
import leadtools.codecs.*; 
import leadtools.imageprocessing.core.*; 
import leadtools.svg.*; 
import leadtools.imageprocessing.CloneCommand; 
import leadtools.imageprocessing.FillCommand; 
import leadtools.imageprocessing.FlipCommand; 
import leadtools.imageprocessing.GrayscaleCommand; 
import leadtools.imageprocessing.color.InvertCommand; 
import leadtools.imageprocessing.color.PosterizeCommand; 
 
 
// A class that derives from RasterImage 
public class MyRasterImage extends RasterImage { 
 
   private int _myData; 
 
   public MyRasterImage(RasterImage src) { 
      super(src); 
      _myData = 0; 
   } 
 
   public int getMyData() { 
      return _myData; 
   } 
 
   public void setMyData(int value) { 
      _myData = value; 
   } 
 
} 
 
public void derivedRasterImageExample() { 
   final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images"; 
   RasterCodecs codecs = new RasterCodecs(); 
   String srcFileName = combine(LEAD_VARS_IMAGES_DIR, "Image1.cmp"); 
   String destFileName = combine(LEAD_VARS_IMAGES_DIR, "Result.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.setPaintGamma(50); // RasterImage property 
   myImage.setMyData(10); // MyRasterImage property 
 
   assertTrue(myImage.getPaintGamma() == 50); 
   assertTrue(myImage.getMyData() == 10); 
 
   // Save it 
   codecs.save(myImage, destFileName, RasterImageFormat.CMP, 0); 
 
   // Clean up 
   myImage.dispose(); 
   codecs.dispose(); 
 
   assertTrue("File unsuccessfully saved to " + destFileName, (new File(destFileName)).exists()); 
   System.out.printf("File saved successfully to %s%n", destFileName); 
} 
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 Assembly

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