LEADTOOLS (Leadtools assembly)

GetPixel Method

Show in webframe
Example 







The zero-based row number of the pixel.
The zero-based column number of the pixel.
Returns the color of the specified pixel.
Syntax
public RasterColor GetPixel( 
   int row,
   int column
)
'Declaration
 
Public Function GetPixel( _
   ByVal row As Integer, _
   ByVal column As Integer _
) As RasterColor
'Usage
 
Dim instance As RasterImage
Dim row As Integer
Dim column As Integer
Dim value As RasterColor
 
value = instance.GetPixel(row, column)
public RasterColor GetPixel( 
   int row,
   int column
)
-(LTRasterColor*)getPixel:(int)row 
                   column:(int)column 
                    error:(NSError**)outError;
            
public RasterColor getPixel(
  int row, 
  int column
)
            
 function Leadtools.RasterImage.GetPixel( 
   row ,
   column 
)
public:
RasterColor GetPixel( 
   int row,
   int column
) 

Parameters

row
The zero-based row number of the pixel.
column
The zero-based column number of the pixel.

Return Value

This method returns a RasterColor value which may represent an index into an image palette, a grayscale value (Medical Imaging only), or red, green, and blue color values. Alpha value for 32 and 64-bit images are also returned.
Remarks

The standard Windows values for RasterColor represent either red, green, and blue color values, or an index into the image palette. A RasterColor value with the RGB value of 0x00BBGGRR represents the blue, green, and red color values for the specified pixel, where 0xBB is the blue value, 0xGG is the green value and 0xRR is the red value. If 0x01000000 is set in the RGB value of RasterColor (0x010000ZZ), the lower 8 bits (0xZZ) represent an index into the image palette which holds the color value.

For 32 and 64-bit images, an alpha value is also available in the image. This method will return the alpha value in the returned RasterColor object A property. For 32-bit images, this will be the exact byte value of the alpha for the pixel. For 64-bit images, the alpha is 16-bit and since RasterColor.A is an 8-bit value, the returned alpha is normalized from its 16-bit value to 8-bit. For other bits/pixel values, the value returned from this method is identical to the value returned from GetPixelColor.

You can use the SetPixel method to assign the returned value to another pixel.

This method uses image coordinates to specify the pixel. Therefore, you must account for the view perspective of the image.

If you specify a pixel that is outside the image or outside the region (if the image has one), this method throws an exception.

This method supports signed/unsigned data images.

The GetPixel function can use the Extended Grayscale mask. For more information, refer to Grayscale Images

For more information, refer to Introduction to Image Processing With LEADTOOLS.

For more information refer to Accounting for View Perspective.

Example
Copy Code  
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 GetSetPixelExample()
   Dim sourceFile As String = Path.Combine(LEAD_VARS.ImagesDir, "Sample1.cmp")
   Dim destFile As String = Path.Combine(LEAD_VARS.ImagesDir, "GetSetPixelExample.png")

   Dim codecs As New RasterCodecs()

   ' Load the source image as 32-bit (with alpha)
   Dim image As RasterImage = codecs.Load(sourceFile, 32, CodecsLoadByteOrder.Bgr, 1, 1)

   ' Loop through each pixel and set its alpha value to 128 (half transparent)
   For row As Integer = 0 To image.Height - 1
      For col As Integer = 0 To image.Width - 1
         Dim color As RasterColor = image.GetPixel(row, col)
         color.A = 128
         image.SetPixel(row, col, color)
      Next
   Next

   ' Save the image as PNG with these new alpha values
   codecs.Save(image, destFile, RasterImageFormat.Png, 32)

   ' Clean up
   image.Dispose()
   codecs.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;
using Leadtools.ImageProcessing.Core;
using Leadtools.ImageProcessing.Color;
using Leadtools.WinForms;
using Leadtools.Dicom;
using Leadtools.Drawing;

      
public void GetSetPixelExample()
{
   string sourceFile = Path.Combine(ImagesPath.Path, "Sample1.cmp");
   string destFile = Path.Combine(ImagesPath.Path, "GetSetPixelExample.png");
   RasterCodecs codecs = new RasterCodecs();

   // Load the source image as 32-bit (with alpha)
   RasterImage image = codecs.Load(sourceFile, 32, CodecsLoadByteOrder.Bgr, 1, 1);

   // Loop through each pixel and set its alpha value to 128 (half transparent)
   for(int row = 0; row < image.Height; row++)
   {
      for(int col = 0; col < image.Width; col++)
      {
         RasterColor color = image.GetPixel(row, col);
         color.A = 128;
         image.SetPixel(row, col, color);
      }
   }

   // Save the image as PNG with these new alpha values
   codecs.Save(image, destFile, RasterImageFormat.Png, 32);

   // Clean up
   image.Dispose();
   codecs.Dispose();
}
RasterImageExamples.prototype.GetSetPixelExample = function () {
   Tools.SetLicense();

   with (Leadtools) {
      with (Leadtools.Codecs) {
         var sourceFile = "Assets\\Sample1.cmp";
         var destFile = "GetSetPixelExample.png";
         var image;

         var codecs = new RasterCodecs();

         // Load the source image as 32-bit (with alpha)
         return Tools.AppInstallFolder().getFileAsync(sourceFile).then(function (loadFile) {
            return codecs.loadAsync(LeadStreamFactory.create(loadFile), 32, CodecsLoadByteOrder.bgr, 1, 1)
         })
            .then(function (img) {
               image = img;

               // Loop through each pixel and set its alpha value to 128 (half transparent)
               for (var row = 0; row < image.height; row++) {
                  for (var col = 0; col < image.width; col++) {
                     var color = image.getPixel(row, col);
                     color.a = 128;
                     image.setPixel(row, col, color);
                  }
               }

               // Save the image as PNG with these new alpha values
               return Tools.AppLocalFolder().createFileAsync(destFile)
            })
            .then(function (saveFile) {
               var saveStream = LeadStreamFactory.create(saveFile);

               return codecs.saveAsync(image, saveStream, RasterImageFormat.png, 32)})
         .then ( function  ( ) {

               // Clean up
               image.close();
               codecs.close();
            });
      }
   }
}
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ImageProcessing;
using Leadtools.ImageProcessing.Core;
using Leadtools.ImageProcessing.Color;
using Leadtools.Dicom;

      
public async Task GetSetPixelExample()
{
   string sourceFile = @"Assets\Sample1.cmp";
   string destFile = @"GetSetPixelExample.png";
   RasterCodecs codecs = new RasterCodecs();

   // Load the source image as 32-bit (with alpha)
   StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(sourceFile);
   RasterImage image = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile), 32, CodecsLoadByteOrder.Bgr, 1, 1);

   // Loop through each pixel and set its alpha value to 128 (half transparent)
   for (int row = 0; row < image.Height; row++)
   {
      for (int col = 0; col < image.Width; col++)
      {
         RasterColor color = image.GetPixel(row, col);
         color.A = 128;
         image.SetPixel(row, col, color);
      }
   }

   // Save the image as PNG with these new alpha values
   StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(destFile);
   ILeadStream saveStream = LeadStreamFactory.Create(saveFile);
   await codecs.SaveAsync(image, saveStream, RasterImageFormat.Png, 32);

   // Clean up
   image.Dispose();
   codecs.Dispose();
}
Requirements

Target Platforms

See Also

Reference

RasterImage Class
RasterImage Members
SetPixel Method

 

 


Products | Support | Contact Us | Copyright Notices

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