←Select platform

SetPixelData(int,int,IntPtr,int) Method

Summary
Changes the data of the specified pixel by copying from an unmanaged memory buffer.
Syntax
C#
C++/CLI
Java
Python
public void SetPixelData( 
   int row, 
   int column, 
   IntPtr data, 
   int dataSize 
) 
public void setPixelData( 
  int row,  
  int column,  
  byte data[],  
  int dataSize 
) 
public: 
void SetPixelData(  
   int row, 
   int column, 
   IntPtr data, 
   int dataSize 
)  
def SetPixelData(self,row,column,data,dataSize): 

Parameters

row
The zero-based row number of the pixel.

column
The zero-based column number of the pixel.

data
Pointer to an unmanaged memory buffer that contains the pixel data to set. This buffer should contain ((BitsPerPixel + 7) / 8) bytes.

dataSize
Size of the  data unmanaged memory buffer.

Remarks

The image memory must be locked when you use this method. Normally, you can call Access to lock the memory before starting an operation that uses this method. Then call Release when the operation is finished.

No transformations are performed on the pixel data.

This method should be called only for 8, 16, 24, 32, 48 and 64-bit images.

Use the GetPixelData method to get data of a specified pixel.

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

For more information refer to Accounting for View Perspective.

Example
C#
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Core; 
using Leadtools.ImageProcessing.Color; 
using Leadtools.Dicom; 
using Leadtools.Drawing; 
using Leadtools.Controls; 
using Leadtools.Svg; 
 
 
public void GetPixelDataExample() 
{ 
   RasterCodecs codecs = new RasterCodecs(); 
   // Load the image 
   RasterImage image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "IMAGE1.CMP")); 
 
   if (image.BitsPerPixel == 24) 
   { 
      byte[] Data; 
      byte Value; 
      int Row = 10, Column = 20; 
 
      image.Access(); 
 
      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); 
 
      image.Release(); 
   } 
 
   codecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir, "IMAGE1_GetPixelData.BMP"), RasterImageFormat.Bmp, 0); 
 
   image.Dispose(); 
   codecs.Dispose(); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
} 
Requirements

Target Platforms

Help Version 23.0.2024.5.22
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

Leadtools Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.