LEADTOOLS (Leadtools assembly)

GetPixelData(Int32,Int32,IntPtr,Int32) Method

Show in webframe
Example 







The zero-based row number of the pixel.
The zero-based column number of the pixel
Pointer to unmanaged memory buffer to copy the pixel data to.
Size of bytes the buffer in data.
Copies the pixel data of the specified pixel into an unmanaged memory buffer.
Syntax
public void GetPixelData( 
   int row,
   int column,
   IntPtr data,
   int dataSize
)
'Declaration
 
Public Overloads Sub GetPixelData( _
   ByVal row As Integer, _
   ByVal column As Integer, _
   ByVal data As IntPtr, _
   ByVal dataSize As Integer _
) 
'Usage
 
Dim instance As RasterImage
Dim row As Integer
Dim column As Integer
Dim data As IntPtr
Dim dataSize As Integer
 
instance.GetPixelData(row, column, data, dataSize)
public void GetPixelData( 
   int row,
   int column,
   IntPtr data,
   int dataSize
)

            
public void getPixelData(
  int row, 
  int column, 
  byte data[], 
  int dataSize
)
            
 function Leadtools.RasterImage.GetPixelData(Int32,Int32,IntPtr,Int32)( 
   row ,
   column ,
   data ,
   dataSize 
)
public:
void GetPixelData( 
   int row,
   int column,
   IntPtr data,
   int dataSize
) 

Parameters

row
The zero-based row number of the pixel.
column
The zero-based column number of the pixel
data
Pointer to unmanaged memory buffer to copy the pixel data to.
dataSize
Size of bytes the buffer in data.
Remarks

No transformations are performed on the pixel data.

The pixel data copied may represent an index into an images's palette, a grayscale value ((Document/Medical only), or red, green, and blue color values.

This method should be called only for 8, 16, 24, 32, 48 and 64-bit images. It works as follows:

The minimum size of the returned byte array is calculated:

(BitsPerPixel + 7) / 8

You can use the SetPixelData(Int32,Int32,IntPtr,Int32) 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.

The SetPixelData(Int32,Int32,IntPtr,Int32) method changes the data of the specified pixel.

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 GetPixelDataExample()
   Dim codecs As RasterCodecs = New RasterCodecs()
   ' Load the image
   Dim image As RasterImage = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "IMAGE1.CMP"))

   If image.BitsPerPixel = 24 Then
      Dim Data As Byte()
      Dim Value As Byte
      Dim Row As Integer = 10, Column As Integer = 20

      Data = image.GetPixelData(Row, Column)
      ' swap the R and B values
      Value = Data(0)
      Data(0) = Data(2)
      Data(2) = Value

      ' put back the transformed pixel
      image.SetPixelData(Row, Column, Data)
   End If

   codecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir, "IMAGE1_GetPixelData.BMP"), RasterImageFormat.Bmp, 0)

   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 GetPixelDataExample()
{
   RasterCodecs codecs = new RasterCodecs();
   // Load the image
   RasterImage image = codecs.Load(Path.Combine(ImagesPath.Path, "IMAGE1.CMP"));
   if(image.BitsPerPixel == 24)
   {
      byte[] Data;
      byte Value;
      int Row = 10, Column = 20;

      Data = image.GetPixelData(Row, Column);
      // swap the R and B values
      Value = Data[0]; Data[0] = Data[2]; Data[2] = Value;

      // put back the transformed pixel
      image.SetPixelData(Row, Column, Data);
   }

   codecs.Save(image, Path.Combine(ImagesPath.Path, "IMAGE1_GetPixelData.BMP"), RasterImageFormat.Bmp, 0);

   image.Dispose();
   codecs.Dispose();
}
RasterImageExamples.prototype.GetPixelDataExample = function () {
   Tools.SetLicense();
   with (Leadtools) {
      with (Leadtools.Codecs) {
         var codecs = new RasterCodecs();
         // Load the image
         var srcFileName = "Assets\\Image1.cmp";
         var image;

         return Tools.AppInstallFolder().getFileAsync(srcFileName).then(function (loadFile) {
            return codecs.loadAsync(LeadStreamFactory.create(loadFile))
         })
            .then(function (img) {
               image = img;

               if (image.bitsPerPixel === 24) {
                  var Data;
                  var Value;
                  var Row = 10, Column = 20;

                  Data = image.getPixelData(Row, Column);
                  // swap the R and B values
                  Value = Data[0]; Data[0] = Data[2]; Data[2] = Value;

                  // put back the transformed pixel
                  image.setPixelData(Row, Column, Data);
               }

               return Tools.AppLocalFolder().createFileAsync("IMAGE1_GetPixelData.BMP")
            })
            .then(function (saveFile) {
               var saveStream = LeadStreamFactory.create(saveFile);
               return codecs.saveAsync(image, saveStream, RasterImageFormat.bmp, 24)
            })
            .then(function () {

               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 GetPixelDataExample()
{
   RasterCodecs codecs = new RasterCodecs();
   // Load the image
   string srcFileName = @"Assets\Image1.cmp";
   StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName);
   RasterImage image = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile));
   if (image.BitsPerPixel == 24)
   {
      byte[] Data;
      byte Value;
      int Row = 10, Column = 20;

      Data = image.GetPixelData(Row, Column);
      // swap the R and B values
      Value = Data[0]; Data[0] = Data[2]; Data[2] = Value;

      // put back the transformed pixel
      image.SetPixelData(Row, Column, Data);
   }

   StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync("IMAGE1_GetPixelData.BMP");
   ILeadStream saveStream = LeadStreamFactory.Create(saveFile);
   await codecs.SaveAsync(image, saveStream, RasterImageFormat.Bmp, 24);

   image.Dispose();
   codecs.Dispose();
}
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Dicom;
using Leadtools.ImageProcessing;
using Leadtools.ImageProcessing.Core;
using Leadtools.ImageProcessing.Color;
using Leadtools.Examples;
using Leadtools.Windows.Media;

public void GetPixelDataExample(RasterImage image, Stream destStream)
{
   if (image.BitsPerPixel == 24)
   {
      byte[] Data;
      byte Value;
      int Row = 10, Column = 20;
      Data = image.GetPixelData(Row, Column);
      // swap the R and B values
      Value = Data[0]; Data[0] = Data[2]; Data[2] = Value;

      // put back the transformed pixel
      image.SetPixelData(Row, Column, Data);
   }

   RasterCodecs codecs = new RasterCodecs();
   codecs.Save(image, destStream, RasterImageFormat.Bmp, 0);

   image.Dispose();
}
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.Dicom
Imports Leadtools.ImageProcessing
Imports Leadtools.ImageProcessing.Core
Imports Leadtools.ImageProcessing.Color
Imports Leadtools.Windows.Media

Public Sub GetPixelDataExample(ByVal image As RasterImage, ByVal destStream As Stream)
   If image.BitsPerPixel = 24 Then
      Dim Data As Byte()
      Dim Value As Byte
      Dim Row As Integer = 10, Column As Integer = 20
      Data = image.GetPixelData(Row, Column)
      ' swap the R and B values
      Value = Data(0)
      Data(0) = Data(2)
      Data(2) = Value

      ' put back the transformed pixel
      image.SetPixelData(Row, Column, Data)
   End If

   Dim codecs As RasterCodecs = New RasterCodecs()
   codecs.Save(image, destStream, RasterImageFormat.Bmp, 0)

   image.Dispose()
End Sub
Requirements

Target Platforms

See Also

Reference

RasterImage Class
RasterImage Members
Overload List

 

 


Products | Support | Contact Us | Copyright Notices

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