Products | Support | Email a link to this topic. | Send comments on this topic. | Back to Introduction - All Topics | Help Version 19.0.6.28
|
Leadtools Namespace > RasterImage Class : GetPixelColor Method |
public RasterColor GetPixelColor( int row, int column )
'Declaration
Public Function GetPixelColor( _ 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.GetPixelColor(row, column)
public RasterColor GetPixelColor( int row, int column )
- (LTRasterColor *)getPixelColorAtRow:(NSInteger)row column:(NSInteger)column
public RasterColor getPixelColor( int row, int column )
public: RasterColor GetPixelColor( int row, int column )
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.
You can use the SetPixelColor 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 does not support alpha values for 32 and 64-bit color images and the alpha value of the returned color should not be used. Instead, use the GetPixel and SetPixel methods.
In the Document and Medical toolkits, the COLORREF value can represent a 16 bit grayscale value if pBitmap is a 12 or 16-bit grayscale bitmap. To avoid confusion with an RGB value, set the COLORREF_GRAY16 mask (0x04000000). In this case (0x0400YYYY), the lower 16 bits (0xYYYY) of the COLORREF value represent the 16-bit grayscale value. (0x0400FFFF is 16-bit white and 0x04000000 is 16-bit black.) This is not a standard Windows value. Therefore, although LEADTOOLS functions will recognize a COLORREF having this format, but Windows functions will not.
This method supports signed/unsigned data images.
For more information, refer to Introduction to Image Processing With LEADTOOLS.
For more information refer to Accounting for View Perspective.
This example uses GetPixelColor and SetPixelColor to invert the colors of the pixels in a line in the upper left part of the displayed image.
Imports Leadtools Imports Leadtools.Codecs Imports Leadtools.ImageProcessing Imports Leadtools.ImageProcessing.Core Imports Leadtools.ImageProcessing.Color Imports Leadtools.Controls Imports Leadtools.Dicom Imports Leadtools.Drawing Imports Leadtools.Svg Public Sub GetPixelColorExample() Dim codecs As RasterCodecs = New RasterCodecs() ' Load the image Dim image As RasterImage = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "IMAGE1.CMP")) ' Specify a line of pixels. Dim Offset As LeadPoint = New LeadPoint(image.Width \ 8, image.Height \ 8) Dim XSize As Integer = image.Width \ 3 ' Invert the colors of pixels in the line. Dim i As Integer = 0 Do While i < XSize Dim OldOffset As LeadPoint = New LeadPoint(Offset.X, Offset.Y) ' Adjust the XOffset and YOffset in case the view perspective is not TopLeft. Offset = image.PointToImage(RasterViewPerspective.TopLeft, Offset) Dim PixelColor As RasterColor = image.GetPixelColor(Offset.Y, Offset.X) PixelColor.R = CByte(255 - PixelColor.R) PixelColor.G = CByte(255 - PixelColor.G) PixelColor.B = CByte(255 - PixelColor.B) image.SetPixelColor(Offset.Y, Offset.X, PixelColor) Offset = OldOffset ' Restore Offset Offset.X = Offset.X + 1 i += 1 Loop codecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir, "IMAGE1_GetPixelColor.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.Dicom; using Leadtools.Drawing; using Leadtools.Controls; using Leadtools.Svg; public void GetPixelColorExample() { RasterCodecs codecs = new RasterCodecs(); // Load the image RasterImage image = codecs.Load(Path.Combine(ImagesPath.Path, "IMAGE1.CMP")); // Specify a line of pixels. LeadPoint offset = new LeadPoint(image.Width / 8, image.Height / 8); int XSize = image.Width / 3; // Invert the colors of pixels in the line. for(int i = 0; i < XSize; i++) { LeadPoint oldOffset = new LeadPoint(offset.X, offset.Y); // Adjust the XOffset and YOffset in case the view perspective is not TopLeft. offset = image.PointToImage(Leadtools.RasterViewPerspective.TopLeft, offset); RasterColor pixelColor = image.GetPixelColor(offset.Y, offset.X); pixelColor.R = (byte)(255 - pixelColor.R); pixelColor.G = (byte)(255 - pixelColor.G); pixelColor.B = (byte)(255 - pixelColor.B); image.SetPixelColor(offset.Y, offset.X, pixelColor); offset = oldOffset; // Restore Offset offset.X = offset.X + 1; } codecs.Save(image, Path.Combine(ImagesPath.Path, "IMAGE1_GetPixelColor.BMP"), RasterImageFormat.Bmp, 0); image.Dispose(); codecs.Dispose(); }
RasterImageExamples.prototype.GetPixelColorExample = 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; // Specify a line of pixels. var offset = LeadPointHelper.create(image.width / 8, image.height / 8); var XSize = image.width / 3; // Invert the colors of pixels in the line. for (var i = 0; i < XSize; i++) { var oldOffset = LeadPointHelper.create(offset.X, offset.Y); // Adjust the XOffset and YOffset in case the view perspective is not TopLeft. offset = image.pointToImage(Leadtools.RasterViewPerspective.topLeft, offset); var pixelColor = image.getPixelColor(offset.y, offset.x); pixelColor.r = Math.max ( 255, Math.min ( 0, (255 - pixelColor.r) ) ); pixelColor.g = Math.max ( 255, Math.min ( 0, (255 - pixelColor.g) ) ) ; pixelColor.b = Math.max ( 255, Math.min ( 0, (255 - pixelColor.b) ) ); image.setPixelColor(offset.y, offset.x, pixelColor); offset = oldOffset; // Restore Offset offset.x = offset.x + 1; } return Tools.AppLocalFolder().createFileAsync("IMAGE1_GetPixelColor.BMP") }) .then(function (saveFile) { var saveStream = LeadStreamFactory.create(saveFile); 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 GetPixelColorExample() { 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)); // Specify a line of pixels. LeadPoint offset = LeadPointHelper.Create(image.Width / 8, image.Height / 8); int XSize = image.Width / 3; // Invert the colors of pixels in the line. for (int i = 0; i < XSize; i++) { LeadPoint oldOffset = LeadPointHelper.Create(offset.X, offset.Y); // Adjust the XOffset and YOffset in case the view perspective is not TopLeft. offset = image.PointToImage(Leadtools.RasterViewPerspective.TopLeft, offset); RasterColor pixelColor = image.GetPixelColor(offset.Y, offset.X); pixelColor.R = (byte)(255 - pixelColor.R); pixelColor.G = (byte)(255 - pixelColor.G); pixelColor.B = (byte)(255 - pixelColor.B); image.SetPixelColor(offset.Y, offset.X, pixelColor); offset = oldOffset; // Restore Offset offset.X = offset.X + 1; } StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync("IMAGE1_GetPixelColor.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 GetPixelColorExample(RasterImage image, Stream destStream) { // Specify a line of pixels. LeadPoint Offset = new LeadPoint(image.Width / 8, image.Height / 8); int XSize = image.Width / 3; // Invert the colors of pixels in the line. for (int i = 0; i < XSize; i++) { LeadPoint OldOffset = new LeadPoint(Offset.X, Offset.Y); // Adjust the XOffset and YOffset in case the view perspective is not TopLeft. Offset = image.PointToImage(Leadtools.RasterViewPerspective.TopLeft, Offset); RasterColor PixelColor = image.GetPixelColor(Offset.Y, Offset.X); PixelColor.R = (byte)(255 - PixelColor.R); PixelColor.G = (byte)(255 - PixelColor.G); PixelColor.B = (byte)(255 - PixelColor.B); image.SetPixelColor(Offset.Y, Offset.X, PixelColor); Offset = OldOffset; // Restore Offset Offset.X = Offset.X + 1; } 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 GetPixelColorExample(ByVal image As RasterImage, ByVal destStream As Stream) ' Specify a line of pixels. Dim Offset As LeadPoint = New LeadPoint(image.Width / 8, image.Height / 8) Dim XSize As Integer = image.Width / 3 ' Invert the colors of pixels in the line. Dim i As Integer = 0 Do While i < XSize Dim OldOffset As LeadPoint = New LeadPoint(Offset.X, Offset.Y) ' Adjust the XOffset and YOffset in case the view perspective is not TopLeft. Offset = image.PointToImage(RasterViewPerspective.TopLeft, Offset) Dim PixelColor As RasterColor = image.GetPixelColor(Offset.Y, Offset.X) PixelColor.R = CByte(255 - PixelColor.R) PixelColor.G = CByte(255 - PixelColor.G) PixelColor.B = CByte(255 - PixelColor.B) image.SetPixelColor(Offset.Y, Offset.X, PixelColor) Offset = OldOffset ' Restore Offset Offset.X = Offset.X + 1 i += 1 Loop Dim codecs As RasterCodecs = New RasterCodecs() codecs.Save(image, destStream, RasterImageFormat.Bmp, 0) image.Dispose() End Sub