LEADTOOLS (Leadtools assembly)

ClearNegativePixelsCommand Class

Show in webframe
Example 







Members 
Sets all pixels with negative color values to 0.
Object Model
Syntax
public class ClearNegativePixelsCommand : RasterCommand, IRasterCommand  
'Declaration
 
Public Class ClearNegativePixelsCommand 
   Inherits RasterCommand
   Implements IRasterCommand 
'Usage
 
Dim instance As ClearNegativePixelsCommand
public sealed class ClearNegativePixelsCommand : IRasterCommand  
@interface LTClearNegativePixelsCommand : LTRasterCommand
public class ClearNegativePixelsCommand extends RasterCommand
function Leadtools.ImageProcessing.ClearNegativePixelsCommand()
public ref class ClearNegativePixelsCommand : public RasterCommand, IRasterCommand  
Remarks

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.

Example
Copy Code  
Imports Leadtools
  Imports Leadtools.Codecs
  Imports Leadtools.ImageProcessing

  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
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ImageProcessing;

      
public void ClearNegativePixelsCommandExample()
{
   RasterCodecs codecs = new RasterCodecs();
   string srcFileName = Path.Combine(ImagesPath.Path, "Image1.cmp");
   string destFileName = Path.Combine(ImagesPath.Path, "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);
   Assert.IsTrue(image.Signed);

   // Clear the negative pixels and save it it back
   ClearNegativePixelsCommand command = new ClearNegativePixelsCommand();
   command.Run(image);
   Assert.IsTrue(!image.Signed);

   codecs.Save(image, destFileName, RasterImageFormat.Tif, 24);

   // Clean up
   image.Dispose();
   codecs.Dispose();
}
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;
                    });
        }
    }
}
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ImageProcessing;

      
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();
}
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Examples;
using Leadtools.ImageProcessing;
using Leadtools.Windows.Media;

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();
}
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.ImageProcessing
Imports Leadtools.Windows.Media

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
Requirements

Target Platforms

See Also

Reference

ClearNegativePixelsCommand Members
Leadtools.ImageProcessing Namespace

 

 


Products | Support | Contact Us | Copyright Notices

© 2006-2014 All Rights Reserved. LEAD Technologies, Inc.