Leadtools Namespace > RasterImage Class > Clone Method : Clone() Method |
public RasterImage Clone()
'Declaration Public Overloads Function Clone() As RasterImage
'Usage Dim instance As RasterImage Dim value As RasterImage value = instance.Clone()
public RasterImage Clone()
-(LTRasterImage*)clone:(NSError**)outError;
public RasterImage clone()
function Leadtools.RasterImage.Clone()()
public: RasterImage^ Clone();
You can also use the RasterImage Constructor(RasterImage) constructor to create an exact copy of an existing RasterImage.
To create a copy of an object while maintaining a progress status, refer to the Leadtools.ImageProcessing.CloneCommand.
This method copies only the current active page and no metadata information is copied. To create an exact copy of a RasterImage object use the CloneAll method.
To clone an image with support for a progress event, refer to Leadtools.ImageProcessing.CloneCommand.
Imports Leadtools Imports Leadtools.Codecs Imports Leadtools.ImageProcessing Imports Leadtools.ImageProcessing.Core Imports Leadtools.ImageProcessing.Color Imports Leadtools.WinForms Imports Leadtools.Dicom Imports Leadtools.Drawing Public Sub CloneExample() Dim codecs As RasterCodecs = New RasterCodecs() Dim srcFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "eye.gif") ' Load the multi-page image Dim srcImage As RasterImage = codecs.Load(srcFileName) Console.WriteLine("Pages in source image: {0}", srcImage.PageCount) ' Use the Clone method to clone this image ' Notice, this method only clones the current active page only Dim destImage1 As RasterImage = srcImage.Clone() Console.WriteLine("Pages in image created with Clone: {0}", destImage1.PageCount) Debug.Assert(destImage1.PageCount = 1) ' Use the Clone rectangle method to clone this image ' Notice, this method also clones the current active page only Dim rc As LeadRect = New LeadRect(0, 0, srcImage.Width \ 2, srcImage.Height \ 2) Console.WriteLine("Cloning with a rectangle = {0}", rc.ToString()) Dim destImage2 As RasterImage = srcImage.Clone(rc) Console.WriteLine("Pages in image created with Clone(LeadRect): {0}", destImage2.PageCount) Console.WriteLine("Image created with Clone(LeadRect) size = {0} by {1}", destImage2.Width, destImage2.Height) Debug.Assert(destImage2.PageCount = 1) Debug.Assert(destImage2.Width = srcImage.Width \ 2) Debug.Assert(destImage2.Height = srcImage.Height \ 2) ' Use the CloneAll method, this should create a copy ' of all the pages Dim destImage3 As RasterImage = srcImage.CloneAll() Console.WriteLine("Pages in image created with CloneAll: {0}", destImage3.PageCount) Debug.Assert(destImage3.PageCount = srcImage.PageCount) ' Use the CloneCommand, this allows you to have a progress ' bar as well as control the memory flags, here ' we will create a destination image using disk memory. Dim cloneCmd As CloneCommand = New CloneCommand() AddHandler cloneCmd.Progress, AddressOf cloneCmd_Progress cloneCmd.CreateFlags = RasterMemoryFlags.Disk cloneCmd.Run(srcImage) RemoveHandler cloneCmd.Progress, AddressOf cloneCmd_Progress Dim destImage4 As RasterImage = cloneCmd.DestinationImage Console.WriteLine("Pages in image created with CloneCommand: {0}", destImage4.PageCount) Console.WriteLine("Disk memory model of image created with CloneCommand: {0}", destImage4.IsDiskMemory) Debug.Assert(destImage4.PageCount = 1) Debug.Assert(destImage4.IsDiskMemory) ' Clean up destImage4.Dispose() destImage3.Dispose() destImage2.Dispose() destImage1.Dispose() srcImage.Dispose() codecs.Dispose() End Sub Private Sub cloneCmd_Progress(ByVal sender As Object, ByVal e As RasterCommandProgressEventArgs) If e.Percent = 0 Then Console.WriteLine("Clone progress started") End If If e.Percent = 100 Then Console.WriteLine("Clone progress ended") End If 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.ImageProcessing; using Leadtools.ImageProcessing.Core; using Leadtools.ImageProcessing.Color; using Leadtools.WinForms; using Leadtools.Dicom; using Leadtools.Drawing; public void CloneExample() { RasterCodecs codecs = new RasterCodecs(); string srcFileName = Path.Combine(ImagesPath.Path, "eye.gif"); // Load the multi-page image RasterImage srcImage = codecs.Load(srcFileName); Console.WriteLine("Pages in source image: {0}", srcImage.PageCount); // Use the Clone method to clone this image // Notice, this method only clones the current active page only RasterImage destImage1 = srcImage.Clone(); Console.WriteLine("Pages in image created with Clone: {0}", destImage1.PageCount); Assert.IsTrue(destImage1.PageCount == 1); // Use the Clone rectangle method to clone this image // Notice, this method also clones the current active page only LeadRect rc = new LeadRect(0, 0, srcImage.Width / 2, srcImage.Height / 2); Console.WriteLine("Cloning with a rectangle = {0}", rc.ToString()); RasterImage destImage2 = srcImage.Clone(rc); Console.WriteLine("Pages in image created with Clone(LeadRect): {0}", destImage2.PageCount); Console.WriteLine("Image created with Clone(LeadRect) size = {0} by {1}", destImage2.Width, destImage2.Height); Assert.IsTrue(destImage2.PageCount == 1); Assert.IsTrue(destImage2.Width == srcImage.Width / 2); Assert.IsTrue(destImage2.Height == srcImage.Height / 2); // Use the CloneAll method, this should create a copy // of all the pages RasterImage destImage3 = srcImage.CloneAll(); Console.WriteLine("Pages in image created with CloneAll: {0}", destImage3.PageCount); Assert.IsTrue(destImage3.PageCount == srcImage.PageCount); // Use the CloneCommand, this allows you to have a progress // bar as well as control the memory flags, here // we will create a destination image using disk memory. CloneCommand cloneCmd = new CloneCommand(); cloneCmd.Progress += new EventHandler<RasterCommandProgressEventArgs>(cloneCmd_Progress); cloneCmd.CreateFlags = RasterMemoryFlags.Disk; cloneCmd.Run(srcImage); cloneCmd.Progress -= new EventHandler<RasterCommandProgressEventArgs>(cloneCmd_Progress); RasterImage destImage4 = cloneCmd.DestinationImage; Console.WriteLine("Pages in image created with CloneCommand: {0}", destImage4.PageCount); Console.WriteLine("Disk memory model of image created with CloneCommand: {0}", destImage4.IsDiskMemory); Assert.IsTrue(destImage4.PageCount == 1); Assert.IsTrue(destImage4.IsDiskMemory); // Clean up destImage4.Dispose(); destImage3.Dispose(); destImage2.Dispose(); destImage1.Dispose(); srcImage.Dispose(); codecs.Dispose(); } void cloneCmd_Progress(object sender, RasterCommandProgressEventArgs e) { if(e.Percent == 0) Console.WriteLine("Clone progress started"); if(e.Percent == 100) Console.WriteLine("Clone progress ended"); }
RasterImageExamples.prototype.CloneExample = function ( ) { Tools.SetLicense(); with ( Leadtools ) { with (Leadtools.Codecs ) { var codecs = new RasterCodecs(); var srcFileName = "Assets\\eye.gif"; // Load the multi-page image return Tools.AppInstallFolder().getFileAsync(srcFileName).then ( function ( loadFile ) { return codecs.loadAsync(LeadStreamFactory.create(loadFile)); } ) .then ( function ( srcImage ) { console.info("Pages in source image: ", srcImage.pageCount); // Use the Clone method to clone this image // Notice, this method only clones the current active page only var destImage1 = srcImage.clone(); console.info("Pages in image created with Clone: ", destImage1.pageCount); console.assert(destImage1.pageCount === 1, "destImage1.PageCount == 1"); // Use the Clone rectangle method to clone this image // Notice, this method also clones the current active page only var rc = LeadRectHelper.create(0, 0, srcImage.width / 2, srcImage.height / 2); console.info("Cloning with a rectangle = ", rc.toString()); var destImage2 = srcImage.clone(rc); console.log("Pages in image created with Clone(LeadRect): ", destImage2.pageCount); console.log("Image created with Clone(LeadRect) size = " + destImage2.width + " by ", destImage2.height); console.assert(destImage2.pageCount == 1, "destImage2.PageCount == 1"); console.assert(destImage2.width === srcImage.width / 2, "destImage2.Width == srcImage.Width / 2"); console.assert(destImage2.height === srcImage.height / 2, "destImage2.height === srcImage.height / 2"); // Use the CloneAll method, this should create a copy // of all the pages var destImage3 = srcImage.cloneAll(); console.info("Pages in image created with CloneAll: ", destImage3.pageCount); console.assert(destImage3.pageCount == srcImage.pageCount, "destImage3.PageCount == srcImage.PageCount"); // Use the CloneCommand, this allows you to have a progress // bar as well as control the memory flags, here // we will create a destination image using disk memory. var cloneCmd = new Leadtools.ImageProcessing.CloneCommand(); cloneCmd.addEventListener ( "progress", cloneCmd_Progress); cloneCmd.createFlags = RasterMemoryFlags.disk; cloneCmd.run(srcImage); cloneCmd.removeEventListener ( "progress", cloneCmd_Progress); var destImage4 = cloneCmd.destinationImage; console.info("Pages in image created with CloneCommand: ", destImage4.pageCount); console.info("Disk memory model of image created with CloneCommand: ", destImage4.isDiskMemory); console.assert(destImage4.pageCount == 1); console.assert(destImage4.isDiskMemory); // Clean up destImage4.close(); destImage3.close(); destImage2.close(); destImage1.close(); srcImage.close(); codecs.close(); } ) ; } } } function cloneCmd_Progress(e) { if (e.percent === 0) console.info("Clone progress started"); if (e.percent == 100) console.info("Clone progress ended"); }
using Leadtools; using Leadtools.Codecs; using Leadtools.ImageProcessing; using Leadtools.ImageProcessing.Core; using Leadtools.ImageProcessing.Color; using Leadtools.Dicom; public async Task CloneExample() { RasterCodecs codecs = new RasterCodecs(); string srcFileName = @"Assets\eye.gif"; // Load the multi-page image StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName); RasterImage srcImage = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile)); Debug.WriteLine("Pages in source image: {0}", srcImage.PageCount); // Use the Clone method to clone this image // Notice, this method only clones the current active page only RasterImage destImage1 = srcImage.Clone(); Debug.WriteLine("Pages in image created with Clone: {0}", destImage1.PageCount); Assert.IsTrue(destImage1.PageCount == 1); // Use the Clone rectangle method to clone this image // Notice, this method also clones the current active page only LeadRect rc = LeadRectHelper.Create(0, 0, srcImage.Width / 2, srcImage.Height / 2); Debug.WriteLine("Cloning with a rectangle = {0}", rc.ToString()); RasterImage destImage2 = srcImage.Clone(rc); Debug.WriteLine("Pages in image created with Clone(LeadRect): {0}", destImage2.PageCount); Debug.WriteLine("Image created with Clone(LeadRect) size = {0} by {1}", destImage2.Width, destImage2.Height); Assert.IsTrue(destImage2.PageCount == 1); Assert.IsTrue(destImage2.Width == srcImage.Width / 2); Assert.IsTrue(destImage2.Height == srcImage.Height / 2); // Use the CloneAll method, this should create a copy // of all the pages RasterImage destImage3 = srcImage.CloneAll(); Debug.WriteLine("Pages in image created with CloneAll: {0}", destImage3.PageCount); Assert.IsTrue(destImage3.PageCount == srcImage.PageCount); // Use the CloneCommand, this allows you to have a progress // bar as well as control the memory flags, here // we will create a destination image using disk memory. CloneCommand cloneCmd = new CloneCommand(); cloneCmd.Progress += new EventHandler<RasterCommandProgressEventArgs>(cloneCmd_Progress); cloneCmd.CreateFlags = RasterMemoryFlags.Disk; cloneCmd.Run(srcImage); cloneCmd.Progress -= new EventHandler<RasterCommandProgressEventArgs>(cloneCmd_Progress); RasterImage destImage4 = cloneCmd.DestinationImage; Debug.WriteLine("Pages in image created with CloneCommand: {0}", destImage4.PageCount); Debug.WriteLine("Disk memory model of image created with CloneCommand: {0}", destImage4.IsDiskMemory); Assert.IsTrue(destImage4.PageCount == 1); Assert.IsTrue(destImage4.IsDiskMemory); // Clean up destImage4.Dispose(); destImage3.Dispose(); destImage2.Dispose(); destImage1.Dispose(); srcImage.Dispose(); codecs.Dispose(); } void cloneCmd_Progress(object sender, RasterCommandProgressEventArgs e) { if (e.Percent == 0) Debug.WriteLine("Clone progress started"); if (e.Percent == 100) Debug.WriteLine("Clone progress ended"); }
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; public void CloneExample(RasterImage image) { RasterImage srcImage = image; // should be a multi-page image (eye.gif) Debug.WriteLine("Pages in source image: {0}", srcImage.PageCount); // Use the Clone method to clone this image // Notice, this method only clones the current active page only RasterImage destImage1 = srcImage.Clone(); Debug.WriteLine("Pages in image created with Clone: {0}", destImage1.PageCount); Debug.Assert(destImage1.PageCount == 1); // Use the Clone rectangle method to clone this image // Notice, this method also clones the current active page only LeadRect rc = new LeadRect(0, 0, srcImage.Width / 2, srcImage.Height / 2); Debug.WriteLine("Cloning with a rectangle = {0}", rc.ToString()); RasterImage destImage2 = srcImage.Clone(rc); Debug.WriteLine("Pages in image created with Clone(Rectangle): {0}", destImage2.PageCount); Debug.WriteLine("Image created with Clone(Rectangle) size = {0} by {1}", destImage2.Width, destImage2.Height); Debug.Assert(destImage2.PageCount == 1); Debug.Assert(destImage2.Width == srcImage.Width / 2); Debug.Assert(destImage2.Height == srcImage.Height / 2); // Use the CloneAll method, this should create a copy // of all the pages RasterImage destImage3 = srcImage.CloneAll(); Debug.WriteLine("Pages in image created with CloneAll: {0}", destImage3.PageCount); Debug.Assert(destImage3.PageCount == srcImage.PageCount); // Use the CloneCommand, this allows you to have a progress // bar as well as control the memory flags, here // we will create a destination image using conventional memory. CloneCommand cloneCmd = new CloneCommand(); cloneCmd.Progress += new EventHandler<RasterCommandProgressEventArgs>(cloneCmd_Progress); cloneCmd.CreateFlags = RasterMemoryFlags.Conventional; cloneCmd.Run(srcImage); cloneCmd.Progress -= new EventHandler<RasterCommandProgressEventArgs>(cloneCmd_Progress); RasterImage destImage4 = cloneCmd.DestinationImage; Debug.WriteLine("Pages in image created with CloneCommand: {0}", destImage4.PageCount); Debug.WriteLine("Disk memory model of image created with CloneCommand: {0}", destImage4.IsDiskMemory); Debug.Assert(destImage4.PageCount == 1); Debug.Assert(destImage4.IsConventionalMemory); // Clean up destImage4.Dispose(); destImage3.Dispose(); destImage2.Dispose(); destImage1.Dispose(); srcImage.Dispose(); } void cloneCmd_Progress(object sender, RasterCommandProgressEventArgs e) { if (e.Percent == 0) Debug.WriteLine("Clone progress started"); if (e.Percent == 100) Debug.WriteLine("Clone progress ended"); }
Imports Leadtools Imports Leadtools.Codecs Imports Leadtools.Dicom Imports Leadtools.ImageProcessing Imports Leadtools.ImageProcessing.Core Imports Leadtools.ImageProcessing.Color Imports Leadtools.Windows.Media Public Sub CloneExample(ByVal image As RasterImage) Dim srcImage As RasterImage = image ' should be a multi-page image (eye.gif) Debug.WriteLine("Pages in source image: {0}", srcImage.PageCount) ' Use the Clone method to clone this image ' Notice, this method only clones the current active page only Dim destImage1 As RasterImage = srcImage.Clone() Debug.WriteLine("Pages in image created with Clone: {0}", destImage1.PageCount) Debug.Assert(destImage1.PageCount = 1) ' Use the Clone rectangle method to clone this image ' Notice, this method also clones the current active page only Dim rc As LeadRect = New LeadRect(0, 0, srcImage.Width / 2, srcImage.Height / 2) Debug.WriteLine("Cloning with a rectangle = {0}", rc.ToString()) Dim destImage2 As RasterImage = srcImage.Clone(rc) Debug.WriteLine("Pages in image created with Clone(Rectangle): {0}", destImage2.PageCount) Debug.WriteLine("Image created with Clone(Rectangle) size = {0} by {1}", destImage2.Width, destImage2.Height) Debug.Assert(destImage2.PageCount = 1) Debug.Assert(destImage2.Width = srcImage.Width / 2) Debug.Assert(destImage2.Height = srcImage.Height / 2) ' Use the CloneAll method, this should create a copy ' of all the pages Dim destImage3 As RasterImage = srcImage.CloneAll() Debug.WriteLine("Pages in image created with CloneAll: {0}", destImage3.PageCount) Debug.Assert(destImage3.PageCount = srcImage.PageCount) ' Use the CloneCommand, this allows you to have a progress ' bar as well as control the memory flags, here ' we will create a destination image using conventional memory. Dim cloneCmd As CloneCommand = New CloneCommand() AddHandler cloneCmd.Progress, AddressOf cloneCmd_Progress cloneCmd.CreateFlags = RasterMemoryFlags.Conventional cloneCmd.Run(srcImage) RemoveHandler cloneCmd.Progress, AddressOf cloneCmd_Progress Dim destImage4 As RasterImage = cloneCmd.DestinationImage Debug.WriteLine("Pages in image created with CloneCommand: {0}", destImage4.PageCount) Debug.WriteLine("Disk memory model of image created with CloneCommand: {0}", destImage4.IsDiskMemory) Debug.Assert(destImage4.PageCount = 1) Debug.Assert(destImage4.IsConventionalMemory) ' Clean up destImage4.Dispose() destImage3.Dispose() destImage2.Dispose() destImage1.Dispose() srcImage.Dispose() End Sub Private Sub cloneCmd_Progress(ByVal sender As Object, ByVal e As RasterCommandProgressEventArgs) If e.Percent = 0 Then Debug.WriteLine("Clone progress started") End If If e.Percent = 100 Then Debug.WriteLine("Clone progress ended") End If End Sub