Leadtools Namespace > RasterImage Class > GetRowColumn Method : GetRowColumn(Int32,Int32,IBuffer,Int32,Int32) Method |
The number of bytes to retrieve. Consider the bits per pixel, and avoid specifying a number that goes past the end of the row.
For a 1-bit image, each byte represents 8 pixels. For a 4-bit image, each byte represents 2 pixels. For an 8-bit image, each byte represents 1 pixel. For a 16-bit image, every 2 bytes represents one pixel. For 24-bit images, every three bytes represents one pixel. For a 32-bit image, every four bytes represents one pixel. For 48-bit images, every six bytes represents one pixel. For 64-bit images, every eight bytes represents one pixel.
You can use the image BitsPerPixel property with integer math to calculate the number of bytes needed for a particular number of pixels. For example
NumberOfBytes = (Image.BitsPerPixel * NumberOfPixels) / 8; if((Image.BitsPerPixel * NumberOfPixels) % 8) NumberOfBytes = NumberOfBytes + 1; // Round up if necessary for a 1- or 4-bit image
public int GetRowColumn( int row, int column, IBuffer buffer, int bufferIndex, int bufferCount )
'Declaration Public Overloads Function GetRowColumn( _ ByVal row As Integer, _ ByVal column As Integer, _ ByVal buffer As IBuffer, _ ByVal bufferIndex As Integer, _ ByVal bufferCount As Integer _ ) As Integer
'Usage Dim instance As RasterImage Dim row As Integer Dim column As Integer Dim buffer As IBuffer Dim bufferIndex As Integer Dim bufferCount As Integer Dim value As Integer value = instance.GetRowColumn(row, column, buffer, bufferIndex, bufferCount)
public int GetRowColumn( int row, int column, IBuffer buffer, int bufferIndex, int bufferCount )
function Leadtools.RasterImage.GetRowColumn(Int32,Int32,IBuffer,Int32,Int32)( row , column , buffer , bufferIndex , bufferCount )
public: int GetRowColumn( int row, int column, IBuffer^ buffer, int bufferIndex, int bufferCount )
The number of bytes to retrieve. Consider the bits per pixel, and avoid specifying a number that goes past the end of the row.
For a 1-bit image, each byte represents 8 pixels. For a 4-bit image, each byte represents 2 pixels. For an 8-bit image, each byte represents 1 pixel. For a 16-bit image, every 2 bytes represents one pixel. For 24-bit images, every three bytes represents one pixel. For a 32-bit image, every four bytes represents one pixel. For 48-bit images, every six bytes represents one pixel. For 64-bit images, every eight bytes represents one pixel.
You can use the image BitsPerPixel property with integer math to calculate the number of bytes needed for a particular number of pixels. For example
NumberOfBytes = (Image.BitsPerPixel * NumberOfPixels) / 8; if((Image.BitsPerPixel * NumberOfPixels) % 8) NumberOfBytes = NumberOfBytes + 1; // Round up if necessary for a 1- or 4-bit image
By using this low-level method to get any part of a row, you can write a procedure that accesses a single pixel or a rectangular area within the image.
This method accepts an offset parameter (column) in pixels and a length (bufferCount) in bytes. Therefore, you must consider the bits per pixel of the image when specifying these parameters. The following table describes the rules:
Bits Per Pixel | Column Offset (in Pixels) | Bytes to Get |
---|---|---|
1 | Must be a multiple of 8 (such as 0, 8, or 16). | Can be any number up to the end of the row. Consider that there are 8 pixels per byte. |
4 | Must be an even number (such as 0, 2, or 4). | Can be any number up to the end of the row. Consider that there are 2 pixels per byte. |
8 | Can be any column within the image. | Can be any number up to the end of the row. Consider that there is 1 pixel per byte. |
16 | Can be any column within the image. | Must be a multiple of 2 (such as 2, 4, or 6), because there are 2 bytes per pixel. |
24 | Can be any column within the image. | Must be a multiple of 3 (such as 3, 6, or 9), because there are 3 bytes per pixel. |
32 | Can be any column within the image. | Must be a multiple of 4 (such as 4, 8, or 12), because there are 4 bytes per pixel. |
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.
Color order is determined by the Order property of the RasterImage object. This value can be RasterByteOrder.Rgb, RasterByteOrder.Bgr, or RasterByteOrder.Romm.
RasterByteOrder.Gray is only valid for 12 and 16-bit grayscale images. Support for 12 and 16-bit grayscale images is only available in the Document/Medical Imaging editions.
For more information, refer to Introduction to Image Processing With LEADTOOLS.
Public Sub GetRowColumnExample() Dim codecs As RasterCodecs = New RasterCodecs() Dim image As RasterImage = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "IMAGE1.CMP")) ' This example does not work with rotated view perspectives. If (image.ViewPerspective <> RasterViewPerspective.TopLeft) OrElse (image.ViewPerspective <> RasterViewPerspective.BottomLeft) Then image.ChangeViewPerspective(RasterViewPerspective.TopLeft) End If ' Specify a rectangle in the top left part of the displayed image. Dim xOffset As Integer = Convert.ToInt32(image.Width / 8) ' Column offset of the rectangle to process. Dim xSize As Integer = Convert.ToInt32(image.Width \ 3) ' Pixel width of the rectangle to process. Dim yOffset As Integer = Convert.ToInt32(image.Height / 8) ' Row offset of the rectangle to process. Dim ySize As Integer = Convert.ToInt32(image.Height \ 3) ' Pixel height of the rectangle to process. ' Adjust the YOffset if the view perspective is bottom left. If image.ViewPerspective = RasterViewPerspective.BottomLeft Then yOffset = image.Height - yOffset - ySize End If ' Allocate the buffer. Dim Buffer As Byte() = New Byte(xSize * 3 - 1) {} ' Invert the colors of pixels in the rectangle. If image.IsGlobalMemory Then image.Access() End If Dim i As Integer = yOffset Do While i < yOffset + ySize image.GetRowColumn(i, xOffset, Buffer, 0, xSize * 3) Dim col As Integer = 0 Do While col < xSize * 3 Buffer(col) = Buffer(col) Xor Convert.ToByte(&HFF) col += 1 Loop image.SetRowColumn(i, xOffset, Buffer, 0, xSize * 3) i += 1 Loop If image.IsGlobalMemory Then image.Release() End If codecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir, "IMAGE1_getrowcol.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
public void GetRowColumnExample() { RasterCodecs codecs = new RasterCodecs(); RasterImage image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "IMAGE1.CMP")); // This example does not work with rotated view perspectives. if((image.ViewPerspective != RasterViewPerspective.TopLeft) || (image.ViewPerspective != RasterViewPerspective.BottomLeft)) image.ChangeViewPerspective(RasterViewPerspective.TopLeft); // Specify a rectangle in the top left part of the displayed image. int xOffset = Convert.ToInt32(image.Width / 8); // Column offset of the rectangle to process. int xSize = Convert.ToInt32(image.Width / 3); // Pixel width of the rectangle to process. int yOffset = Convert.ToInt32(image.Height / 8); // Row offset of the rectangle to process. int ySize = Convert.ToInt32(image.Height / 3); // Pixel height of the rectangle to process. // Adjust the YOffset if the view perspective is bottom left. if(image.ViewPerspective == RasterViewPerspective.BottomLeft) yOffset = image.Height - yOffset - ySize; // Allocate the buffer. byte[] Buffer = new byte[xSize * 3]; // Invert the colors of pixels in the rectangle. if(image.IsGlobalMemory) image.Access(); for(int i = yOffset; i < yOffset + ySize; i++) { image.GetRowColumn(i, xOffset, Buffer, 0, xSize * 3); for(int col = 0; col < xSize * 3; col++) Buffer[col] ^= 0xFF; image.SetRowColumn(i, xOffset, Buffer, 0, xSize * 3); } if(image.IsGlobalMemory) image.Release(); codecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir, "IMAGE1_getrowcol.BMP"), RasterImageFormat.Bmp, 0); image.Dispose(); codecs.Dispose(); } static class LEAD_VARS { public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images"; }
RasterImageExamples.prototype.GetRowColumnExample = function () { Tools.SetLicense(); with (Leadtools) { with (Leadtools.Codecs) { var codecs = new RasterCodecs(); 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; // This example does not work with rotated view perspectives. if ((image.viewPerspective != RasterViewPerspective.topLeft) || (image.viewPerspective != RasterViewPerspective.bottomLeft)) image.changeViewPerspective(RasterViewPerspective.topLeft); // Specify a rectangle in the top left part of the displayed image. var xOffset = Math.floor(image.width / 8); // Column offset of the rectangle to process. var xSize = Math.floor(image.width / 3); // Pixel width of the rectangle to process. var yOffset = Math.floor(image.height / 8); // Row offset of the rectangle to process. var ySize = Math.floor(image.height / 3); // Pixel height of the rectangle to process. // Adjust the YOffset if the view perspective is bottom left. if (image.viewPerspective == RasterViewPerspective.bottomLeft) yOffset = image.height - yOffset - ySize; // Allocate the buffer. var Buffer = new Array(xSize * 3); // Invert the colors of pixels in the rectangle. if (image.isGlobalMemory) image.accessData(); for (var i = yOffset; i < yOffset + ySize; i++) { image.getRowColumn(i, xOffset, Buffer, 0, xSize * 3); for (var col = 0; col < xSize * 3; col++) Buffer[col] ^= 0xFF; image.setRowColumn(i, xOffset, Buffer, 0, xSize * 3); } if (image.isGlobalMemory) image.releaseData(); return Tools.AppLocalFolder().createFileAsync("IMAGE1_getrowcol.BMP") }) .then(function (saveFile) { var saveStream = LeadStreamFactory.create(saveFile); return codecs.saveAsync(image, saveStream, RasterImageFormat.bmp, 24) }) .then(function () { image.close(); codecs.close(); }); } } }
[TestMethod] public async Task GetRowColumnExample() { RasterCodecs codecs = new RasterCodecs(); string srcFileName = @"Assets\Image1.cmp"; StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName); RasterImage image = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile)); // This example does not work with rotated view perspectives. if ((image.ViewPerspective != RasterViewPerspective.TopLeft) || (image.ViewPerspective != RasterViewPerspective.BottomLeft)) image.ChangeViewPerspective(RasterViewPerspective.TopLeft); // Specify a rectangle in the top left part of the displayed image. int xOffset = Convert.ToInt32(image.Width / 8); // Column offset of the rectangle to process. int xSize = Convert.ToInt32(image.Width / 3); // Pixel width of the rectangle to process. int yOffset = Convert.ToInt32(image.Height / 8); // Row offset of the rectangle to process. int ySize = Convert.ToInt32(image.Height / 3); // Pixel height of the rectangle to process. // Adjust the YOffset if the view perspective is bottom left. if (image.ViewPerspective == RasterViewPerspective.BottomLeft) yOffset = image.Height - yOffset - ySize; // Allocate the buffer. byte[] Buffer = new byte[xSize * 3]; // Invert the colors of pixels in the rectangle. if (image.IsGlobalMemory) image.AccessData(); for (int i = yOffset; i < yOffset + ySize; i++) { image.GetRowColumn(i, xOffset, Buffer, 0, xSize * 3); for (int col = 0; col < xSize * 3; col++) Buffer[col] ^= 0xFF; image.SetRowColumn(i, xOffset, Buffer, 0, xSize * 3); } if (image.IsGlobalMemory) image.ReleaseData(); StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync("IMAGE1_getrowcol.BMP"); ILeadStream saveStream = LeadStreamFactory.Create(saveFile); await codecs.SaveAsync(image, saveStream, RasterImageFormat.Bmp, 24); image.Dispose(); codecs.Dispose(); }
public void GetRowColumnExample(RasterImage image, Stream destStream) { // This example does not work with rotated view perspectives. if ((image.ViewPerspective != RasterViewPerspective.TopLeft) || (image.ViewPerspective != RasterViewPerspective.BottomLeft)) image.ChangeViewPerspective(RasterViewPerspective.TopLeft); // Specify a rectangle in the top left part of the displayed image. int xOffset = Convert.ToInt32(image.Width / 8); // Column offset of the rectangle to process. int xSize = Convert.ToInt32(image.Width / 3); // Pixel width of the rectangle to process. int yOffset = Convert.ToInt32(image.Height / 8); // Row offset of the rectangle to process. int ySize = Convert.ToInt32(image.Height / 3); // Pixel height of the rectangle to process. // Adjust the YOffset if the view perspective is bottom left. if (image.ViewPerspective == RasterViewPerspective.BottomLeft) yOffset = image.Height - yOffset - ySize; // Allocate the buffer. byte[] Buffer = new byte[xSize * 3]; // Invert the colors of pixels in the rectangle. if (image.IsGlobalMemory) image.Access(); for (int i = yOffset; i < yOffset + ySize; i++) { image.GetRowColumn(i, xOffset, Buffer, 0, xSize * 3); for (int col = 0; col < xSize * 3; col++) Buffer[col] ^= 0xFF; image.SetRowColumn(i, xOffset, Buffer, 0, xSize * 3); } if (image.IsGlobalMemory) image.Release(); RasterCodecs codecs = new RasterCodecs(); codecs.Save(image, destStream, RasterImageFormat.Bmp, 0); image.Dispose(); }
Public Sub GetRowColumnExample(ByVal image As RasterImage, ByVal destStream As Stream)
' This example does not work with rotated view perspectives.
If (image.ViewPerspective <> RasterViewPerspective.TopLeft) OrElse (image.ViewPerspective <> RasterViewPerspective.BottomLeft) Then
image.ChangeViewPerspective(RasterViewPerspective.TopLeft)
End If
' Specify a rectangle in the top left part of the displayed image.
Dim xOffset As Integer = Convert.ToInt32(image.Width / 8) ' Column offset of the rectangle to process.
Dim xSize As Integer = Convert.ToInt32(image.Width / 3) ' Pixel width of the rectangle to process.
Dim yOffset As Integer = Convert.ToInt32(image.Height / 8) ' Row offset of the rectangle to process.
Dim ySize As Integer = Convert.ToInt32(image.Height / 3) ' Pixel height of the rectangle to process.
' Adjust the YOffset if the view perspective is bottom left.
If image.ViewPerspective = RasterViewPerspective.BottomLeft Then
yOffset = image.Height - yOffset - ySize
End If
' Allocate the buffer.
Dim Buffer As Byte() = New Byte(xSize * 3 - 1){}
' Invert the colors of pixels in the rectangle.
If image.IsGlobalMemory Then
image.Access()
End If
Dim i As Integer = yOffset
Do While i < yOffset + ySize
image.GetRowColumn(i, xOffset, Buffer, 0, xSize * 3)
Dim col As Integer = 0
Do While col < xSize * 3
Buffer(col) = Buffer(col) Xor &HFF
col += 1
Loop
image.SetRowColumn(i, xOffset, Buffer, 0, xSize * 3)
i += 1
Loop
If image.IsGlobalMemory Then
image.Release()
End If
Dim codecs As RasterCodecs = New RasterCodecs()
codecs.Save(image, destStream, RasterImageFormat.Bmp, 0)
image.Dispose()
End Sub
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2