Creates an exact copy of the current page of this
RasterImage.
Syntax
Visual Basic (Declaration) | |
---|
Public Overloads Function Clone() As RasterImage |
Return Value
The
RasterImage this method creates.
Example
This example loads a multi-page image and clones it in 3 different ways.
Visual Basic | Copy Code |
---|
Public Sub CloneExample()
RasterCodecs.Startup()
Dim codecs As RasterCodecs = New RasterCodecs()
Dim srcFileName As String = LeadtoolsExamples.Common.ImagesPath.Path + "eye.gif"
Dim srcImage As RasterImage = codecs.Load(srcFileName)
Console.WriteLine("Pages in source image: {0}", srcImage.PageCount)
Dim destImage1 As RasterImage = srcImage.Clone()
Console.WriteLine("Pages in image created with Clone: {0}", destImage1.PageCount)
Debug.Assert(destImage1.PageCount = 1)
Dim rc As Rectangle = New Rectangle(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(Rectangle): {0}", destImage2.PageCount)
Console.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)
Dim destImage3 As RasterImage = srcImage.CloneAll()
Console.WriteLine("Pages in image created with CloneAll: {0}", destImage3.PageCount)
Debug.Assert(destImage3.PageCount = srcImage.PageCount)
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)
destImage4.Dispose()
destImage3.Dispose()
destImage2.Dispose()
destImage1.Dispose()
srcImage.Dispose()
codecs.Dispose()
RasterCodecs.Shutdown()
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 |
C# | Copy Code |
---|
public void CloneExample() { RasterCodecs.Startup(); RasterCodecs codecs = new RasterCodecs(); string srcFileName = LeadtoolsExamples.Common.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); Debug.Assert(destImage1.PageCount == 1); // Use the Clone rectangle method to clone this image // Notice, this method also clones the current active page only Rectangle rc = new Rectangle(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(Rectangle): {0}", destImage2.PageCount); Console.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(); 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. 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); Debug.Assert(destImage4.PageCount == 1); Debug.Assert(destImage4.IsDiskMemory); // Clean up destImage4.Dispose(); destImage3.Dispose(); destImage2.Dispose(); destImage1.Dispose(); srcImage.Dispose(); codecs.Dispose(); RasterCodecs.Shutdown(); } 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"); } |
Remarks
Requirements
Target Platforms: Microsoft .NET Framework 3.0, Windows XP, Windows Server 2003 family, Windows Server 2008 family
See Also