Leadtools.ImageProcessing Namespace : ClearNegativePixelsCommand Class |
public class ClearNegativePixelsCommand : RasterCommand, IRasterCommand
'Declaration Public Class ClearNegativePixelsCommand Inherits RasterCommand Implements IRasterCommand
'Usage Dim instance As ClearNegativePixelsCommand
public sealed class ClearNegativePixelsCommand : IRasterCommand
function Leadtools.ImageProcessing.ClearNegativePixelsCommand()
public ref class ClearNegativePixelsCommand : public RasterCommand, IRasterCommand
If CodecsLoadOptions.Signed is true when a file is loaded, the image may contain negative pixel values and LEADTOOLS will paint/process the image incorrectly. In order to use this image correctly, you must user ClearNegativePixelsCommand. If the CodecsLoadOptions.Signed property is false, all negative pixels are cleared internally, during the load process.
Since some TIFF files are saved with negative values for pixel colors, you should use ClearNegativePixelsCommand if, after loading an image, RasterImage.Signed is true. ClearNegativePixelsCommand does nothing if RasterImage.IsSigned is false.
Programming tip: use ClearNegativePixelsCommand right after loading the image from file.
For more information, refer to Introduction to Image Processing With LEADTOOLS.
Public Sub ClearNegativePixelsCommandExample() 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, "CleanNegativePixelsCommand.tif") ' Load the CMP file and convert it to TIF Dim image As RasterImage = codecs.Load(srcFileName) image.Signed = True codecs.Save(image, destFileName, RasterImageFormat.Tif, 24) image.Dispose() ' Load this image as signed codecs.Options.Load.Signed = True ' Load the source image from disk image = codecs.Load(destFileName) Debug.Assert(image.Signed) ' Clear the negative pixels and save it it back Dim command As ClearNegativePixelsCommand = New ClearNegativePixelsCommand() command.Run(image) Debug.Assert((Not image.Signed)) codecs.Save(image, destFileName, RasterImageFormat.Tif, 24) ' Clean up image.Dispose() End Sub Public NotInheritable Class LEAD_VARS Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" End Class
public void ClearNegativePixelsCommandExample() { RasterCodecs codecs = new RasterCodecs(); string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp"); string destFileName = Path.Combine(LEAD_VARS.ImagesDir, "CleanNegativePixelsCommand.tif"); // Load the CMP file and convert it to TIF RasterImage image = codecs.Load(srcFileName); image.Signed = true; codecs.Save(image, destFileName, RasterImageFormat.Tif, 24); image.Dispose(); // Load this image as signed codecs.Options.Load.Signed = true; // Load the source image from disk image = codecs.Load(destFileName); Debug.Assert(image.Signed); // Clear the negative pixels and save it it back ClearNegativePixelsCommand command = new ClearNegativePixelsCommand(); command.Run(image); Debug.Assert(!image.Signed); codecs.Save(image, destFileName, RasterImageFormat.Tif, 24); // Clean up image.Dispose(); } static class LEAD_VARS { public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images"; }
RasterCommandExamples.prototype.ClearNegativePixelsCommandExample = function () { Tools.SetLicense(); with (Leadtools) { with (Leadtools.Codecs) { var codecs = new RasterCodecs(); var srcFileName = "Assets\\Image1.cmp"; var destFileName1 = "CleanNegativePixelsCommand1.tif"; var destFileName2 = "CleanNegativePixelsCommand2.tif"; var image; // Load the CMP file and convert it to TIF return Tools.AppInstallFolder().getFileAsync(srcFileName).then(function (loadFile) { return codecs.loadAsync(LeadStreamFactory.create(loadFile), 24, CodecsLoadByteOrder.bgr, 1, 1) }) .then(function (img) { image = img; image.signed = true; return Tools.AppLocalFolder().createFileAsync(destFileName1) }) .then(function (saveFile) { return codecs.saveAsync(image, LeadStreamFactory.create(saveFile), RasterImageFormat.tif, 24) }) .then(function () { image.close(); // Load this image as signed codecs.options.load.signed = true; // Load the source image from disk return Tools.AppLocalFolder().getFileAsync(destFileName1) }) .then(function (loadFile) { return codecs.loadAsync(LeadStreamFactory.create(loadFile), 24, CodecsLoadByteOrder.bgr, 1, 1) }) .then(function (img) { image = img; console.assert(image.signed); // Clear the negative pixels and save it it back var command = new Leadtools.ImageProcessing.ClearNegativePixelsCommand(); command.run(image); console.assert(!image.signed, "!image.signed"); return Tools.AppLocalFolder().createFileAsync(destFileName2) }) .then(function (saveFile) { return codecs.saveAsync(image, LeadStreamFactory.create(saveFile), RasterImageFormat.tif, 24) }) .then(function () { // Clean up image.close(); codecs.close; }); } } }
[TestMethod] public async Task ClearNegativePixelsCommandExample() { RasterCodecs codecs = new RasterCodecs(); string srcFileName = @"Assets\Image1.cmp"; string destFileName1 = @"CleanNegativePixelsCommand1.tif"; string destFileName2 = @"CleanNegativePixelsCommand2.tif"; // Load the CMP file and convert it to TIF StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName); RasterImage image = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile), 24, CodecsLoadByteOrder.Bgr, 1, 1); image.Signed = true; StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(destFileName1); await codecs.SaveAsync(image, LeadStreamFactory.Create(saveFile), RasterImageFormat.Tif, 24); image.Dispose(); // Load this image as signed codecs.Options.Load.Signed = true; // Load the source image from disk loadFile = await Tools.AppLocalFolder.GetFileAsync(destFileName1); image = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile), 24, CodecsLoadByteOrder.Bgr, 1, 1); Assert.IsTrue(image.Signed); // Clear the negative pixels and save it it back ClearNegativePixelsCommand command = new ClearNegativePixelsCommand(); command.Run(image); Assert.IsTrue(!image.Signed); saveFile = await Tools.AppLocalFolder.CreateFileAsync(destFileName2); await codecs.SaveAsync(image, LeadStreamFactory.Create(saveFile), RasterImageFormat.Tif, 24); // Clean up image.Dispose(); }
public void ClearNegativePixelsCommandExample(RasterImage image, Stream destStream) { RasterCodecs codecs = new RasterCodecs(); // convert it to TIF image.Signed = true; codecs.Save(image, destStream, RasterImageFormat.Tif, 24); image.Dispose(); // Load this image as signed codecs.Options.Load.Signed = true; // Load the source image image = codecs.Load(destStream); Debug.Assert(image.Signed); // Clear the negative pixels and save it it back ClearNegativePixelsCommand command = new ClearNegativePixelsCommand(); command.Run(image); Debug.Assert(!image.Signed); codecs.Save(image, destStream, RasterImageFormat.Tif, 24); // Clean up image.Dispose(); }
Public Sub ClearNegativePixelsCommandExample(ByVal image As RasterImage, ByVal destStream As Stream)
Dim codecs As RasterCodecs = New RasterCodecs()
' convert it to TIF
image.Signed = True
codecs.Save(image, destStream, RasterImageFormat.Tif, 24)
image.Dispose()
' Load this image as signed
codecs.Options.Load.Signed = True
' Load the source image
image = codecs.Load(destStream)
Debug.Assert(image.Signed)
' Clear the negative pixels and save it it back
Dim command As ClearNegativePixelsCommand = New ClearNegativePixelsCommand()
command.Run(image)
Debug.Assert((Not image.Signed))
codecs.Save(image, destStream, RasterImageFormat.Tif, 24)
' Clean up
image.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