Returns the pixel data of the specified pixel.
Public Overloads Function GetPixelData( _ByVal row As Integer, _ByVal column As Integer _) As Byte()
- (BOOL)getData:(void *)dataofSize:(unsigned long)sizeforPixelAtRow:(NSInteger)rowcolumn:(NSInteger)columnerror:(NSError **)error
function Leadtools.RasterImage.GetPixelData(Int32,Int32)(row ,column)
row
The zero-based row number of the pixel.
column
The zero-based column number of the pixel
This method returns a byte array which may represent an index into an images's palette, a grayscale value (Document/Medical only), or red, green, and blue color values.
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. It works as follows:
The minimum size of the returned byte array is calculated:
(BitsPerPixel + 7) / 8
You can use the SetPixelData 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 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.
This example uses the GetPixelData and SetPixelData methods to swap the R and G values for a particular pixel.
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 LeadtoolsExamples.Common;using Leadtools.Svg;public void GetPixelDataExample(){RasterCodecs codecs = new RasterCodecs();// Load the imageRasterImage image = codecs.Load(Path.Combine(ImagesPath.Path, "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 valuesValue = Data[0]; Data[0] = Data[2]; Data[2] = Value;// put back the transformed pixelimage.SetPixelData(Row, Column, Data);image.Release();}codecs.Save(image, Path.Combine(ImagesPath.Path, "IMAGE1_GetPixelData.BMP"), RasterImageFormat.Bmp, 0);image.Dispose();codecs.Dispose();}
Imports LeadtoolsImports Leadtools.CodecsImports Leadtools.ImageProcessingImports Leadtools.ImageProcessing.CoreImports Leadtools.ImageProcessing.ColorImports Leadtools.ControlsImports Leadtools.DicomImports Leadtools.DrawingImports Leadtools.SvgPublic Sub GetPixelDataExample()Dim codecs As RasterCodecs = New RasterCodecs()' Load the imageDim image As RasterImage = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "IMAGE1.CMP"))If image.BitsPerPixel = 24 ThenDim Data As Byte()Dim Value As ByteDim Row As Integer = 10, Column As Integer = 20image.Access()Data = image.GetPixelData(Row, Column)' swap the R and B valuesValue = Data(0)Data(0) = Data(2)Data(2) = Value' put back the transformed pixelimage.SetPixelData(Row, Column, Data)image.Release()End Ifcodecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir, "IMAGE1_GetPixelData.BMP"), RasterImageFormat.Bmp, 0)image.Dispose()codecs.Dispose()End SubPublic NotInheritable Class LEAD_VARSPublic Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"End Class
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;image.Access();Data = image.GetPixelData(Row, Column);// swap the R and B valuesValue = Data[0]; Data[0] = Data[2]; Data[2] = Value;// put back the transformed pixelimage.SetPixelData(Row, Column, Data);image.Release();}RasterCodecs codecs = new RasterCodecs();codecs.Save(image, destStream, RasterImageFormat.Bmp, 0);image.Dispose();}
Imports LeadtoolsImports Leadtools.CodecsImports Leadtools.DicomImports Leadtools.ImageProcessingImports Leadtools.ImageProcessing.CoreImports Leadtools.ImageProcessing.ColorImports Leadtools.Windows.MediaPublic Sub GetPixelDataExample(ByVal image As RasterImage, ByVal destStream As Stream)If image.BitsPerPixel = 24 ThenDim Data As Byte()Dim Value As ByteDim Row As Integer = 10, Column As Integer = 20image.Access()Data = image.GetPixelData(Row, Column)' swap the R and B valuesValue = Data(0)Data(0) = Data(2)Data(2) = Value' put back the transformed pixelimage.SetPixelData(Row, Column, Data)image.Release()End IfDim codecs As RasterCodecs = New RasterCodecs()codecs.Save(image, destStream, RasterImageFormat.Bmp, 0)image.Dispose()End Sub
Raster .NET | C API | C++ Class Library | JavaScript HTML5
Document .NET | C API | C++ Class Library | JavaScript HTML5
Medical .NET | C API | C++ Class Library | JavaScript HTML5
Medical Web Viewer .NET
