Leadtools.ImageProcessing Namespace : CopyDataCommand Class |
public class CopyDataCommand : RasterCommand, IRasterCommand
'Declaration Public Class CopyDataCommand Inherits RasterCommand Implements IRasterCommand
'Usage Dim instance As CopyDataCommand
public sealed class CopyDataCommand : IRasterCommand
function Leadtools.ImageProcessing.CopyDataCommand()
public ref class CopyDataCommand : public RasterCommand, IRasterCommand
The destination image must accurately identify the copied data. Therefore, the following properties must specify the same values for both the source and destination images:
The CopyDataCommand works by copying the image data from the image passed to the RasterCommand.Run method to the image passed in the DestinationImage property.
Public Sub CopyDataCommandExample() Dim codecs As RasterCodecs = New RasterCodecs() Dim srcFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp") Dim destFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "CopyDataCommand.bmp") ' Load the source image from disk Dim srcImage As RasterImage = codecs.Load(srcFileName) ' Create the destination image with same dimension as the source image Dim destImage As RasterImage = New RasterImage(RasterMemoryFlags.Conventional, srcImage.Width, srcImage.Height, srcImage.BitsPerPixel, srcImage.Order, srcImage.ViewPerspective, srcImage.GetPalette(), IntPtr.Zero, 0) ' Copy the image data from the source image to the destination image Dim command As CopyDataCommand = New CopyDataCommand() command.DestinationImage = destImage command.Run(srcImage) ' Save it to disk codecs.Save(destImage, destFileName, RasterImageFormat.Bmp, 24) ' Clean Up srcImage.Dispose() destImage.Dispose() End Sub Public NotInheritable Class LEAD_VARS Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" End Class
public void CopyDataCommandExample() { RasterCodecs codecs = new RasterCodecs(); string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp"); string destFileName = Path.Combine(LEAD_VARS.ImagesDir, "CopyDataCommand.bmp"); // Load the source image from disk RasterImage srcImage = codecs.Load(srcFileName); // Create the destination image with same dimension as the source image RasterImage destImage = new RasterImage( RasterMemoryFlags.Conventional, srcImage.Width, srcImage.Height, srcImage.BitsPerPixel, srcImage.Order, srcImage.ViewPerspective, srcImage.GetPalette(), IntPtr.Zero, 0); // Copy the image data from the source image to the destination image CopyDataCommand command = new CopyDataCommand(); command.DestinationImage = destImage; command.Run(srcImage); // Save it to disk codecs.Save(destImage, destFileName, RasterImageFormat.Bmp, 24); // Clean Up srcImage.Dispose(); destImage.Dispose(); } static class LEAD_VARS { public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images"; }
RasterCommandExamples.prototype.CopyDataCommandExample = function () { Tools.SetLicense(); with (Leadtools) { with (Leadtools.Codecs) { with (Leadtools.ImageProcessing) { var codecs = new RasterCodecs(); var srcFileName = "Assets\\Image1.cmp"; var destFileName = "CopyDataCommand.bmp"; var srcImage; var destImage; // Load the source image from disk return Tools.AppInstallFolder().getFileAsync(srcFileName).then(function (loadFile) { return codecs.loadAsync(LeadStreamFactory.create(loadFile)) }) .then(function (img) { srcImage = img; // Create the destination image with same dimension as the source image destImage = new RasterImage( RasterMemoryFlags.conventional, srcImage.width, srcImage.height, srcImage.bitsPerPixel, srcImage.order, srcImage.viewPerspective, srcImage.getPalette()); // Copy the image data from the source image to the destination image var command = new CopyDataCommand(); command.destinationImage = destImage; command.run(srcImage); // Save it to disk return Tools.AppLocalFolder().createFileAsync(destFileName) }) .then(function (saveFile) { return codecs.saveAsync(destImage, LeadStreamFactory.create(saveFile), RasterImageFormat.bmp, 24) }) .then(function () { // Clean Up srcImage.close(); destImage.close(); codecs.close(); }); } } } }
[TestMethod] public async Task CopyDataCommandExample() { RasterCodecs codecs = new RasterCodecs(); string srcFileName = @"Assets\Image1.cmp"; string destFileName = @"CopyDataCommand.bmp"; // Load the source image from disk StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName); RasterImage srcImage = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile)); // Create the destination image with same dimension as the source image RasterImage destImage = new RasterImage( RasterMemoryFlags.Conventional, srcImage.Width, srcImage.Height, srcImage.BitsPerPixel, srcImage.Order, srcImage.ViewPerspective, srcImage.GetPalette()); // Copy the image data from the source image to the destination image CopyDataCommand command = new CopyDataCommand(); command.DestinationImage = destImage; command.Run(srcImage); // Save it to disk StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(destFileName); await codecs.SaveAsync(destImage, LeadStreamFactory.Create(saveFile), RasterImageFormat.Bmp, 24); // Clean Up srcImage.Dispose(); destImage.Dispose(); }
public void CopyDataCommandExample(RasterImage srcImage, Stream destStream) { RasterCodecs codecs = new RasterCodecs(); // Create the destination image with same dimension as the source image RasterImage destImage = new RasterImage( RasterMemoryFlags.Conventional, srcImage.Width, srcImage.Height, srcImage.BitsPerPixel, srcImage.Order, srcImage.ViewPerspective, srcImage.GetPalette(), null, 0); // Copy the image data from the source image to the destination image CopyDataCommand command = new CopyDataCommand(); command.DestinationImage = destImage; command.Run(srcImage); // Save it to disk codecs.Save(destImage, destStream, RasterImageFormat.Bmp, 24); // Clean Up srcImage.Dispose(); destImage.Dispose(); }
Public Sub CopyDataCommandExample(ByVal srcImage As RasterImage, ByVal destStream As Stream)
Dim codecs As RasterCodecs = New RasterCodecs()
' Create the destination image with same dimension as the source image
Dim destImage As RasterImage = New RasterImage(RasterMemoryFlags.Conventional, srcImage.Width, srcImage.Height, srcImage.BitsPerPixel, srcImage.Order, srcImage.ViewPerspective, srcImage.GetPalette(), Nothing, 0)
' Copy the image data from the source image to the destination image
Dim command As CopyDataCommand = New CopyDataCommand()
command.DestinationImage = destImage
command.Run(srcImage)
' Save it to disk
codecs.Save(destImage, destStream, RasterImageFormat.Bmp, 24)
' Clean Up
srcImage.Dispose()
destImage.Dispose()
End Sub
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2