LEADTOOLS Support
Imaging
Imaging SDK Questions
Pixel-by-pixel processing of 16-bit grayscale in .NET
This topic and its replies were posted before the current version of LEADTOOLS was released and may no longer be applicable.
#1
Posted
:
Monday, February 27, 2006 12:43:39 AM(UTC)
Groups: Registered
Posts: 1
High everybody! [:D]
I'm using C# .NET for processing some 8-bit grayscale images. The appropriate .NET pixel format used was PixelFormat.Format8bppIndexed. I could access separate pixels by locking a bitmap inside unsafe block and then work with pixels directly as an array of bytes.
Then I decided to upgrade my program to process 16-bit grayscale images. Sadly, .NET format PixelFormat.Format16bppGrayScale is not functioning at all. So I gave a try to Leadtools 14.5 Raster Imaging Pro! But it turned out that I need to go back to .NET Bitmap in order to process it pixel-by-pixel [<:o)] like this:
IRasterImage srcImage;
...
if(srcImage.TestGdiPlusCompatible()
{
Bitmap bmpImage = (Bitmap) srcImage.ChangeToGdiPlusImage(ChangeToGdiPlusImageFlags.None);
BitmapData bmpData = bmpImage.LockBits(
new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, bmpImage.PixelFormat);
unsafe
{
byte* bmp = (byte *) bmpData.Scan0.ToPointer();
// DO ALL PIXEL-WISE STUFF HERE...
// ...
}
bmpImage.UnlockBits(bmpData);
}
OK then, but it didn't work with 16-bit anyway! For instance, when I load 16-bit grayscale TIFF or PNG into srcImage, I get that my image is NOT GDI+ compatible [U]
And if I set the conversion flag to ChangeToGdiPlusImageFlags.ForceChange, it results in a 24-bit RGB bmpImage bitmap.
So, the question is:
How to process 16-bit grayscale images in Leadtools .NET pixel-by-pixel ?
I'm looking forward for your replies [B]
#2
Posted
:
Tuesday, February 28, 2006 5:09:16 AM(UTC)
Groups: Manager, Tech Support
Posts: 367
Was thanked: 1 time(s) in 1 post(s)
Unlike LEADTOOLS Document Imaging, GDI bitmaps do not support 16 bit
grayscale. However you do NOT need to convert to a GID bitmap to get
the pixel data. There are several ways to do it. The easiest is to use
the Leadtools.IRasterImage.GetPixelData method. Here's a simple code
sample:
Leadtools.IRasterImage rasterImage = codecs.Load("16bitGrayscale.tif");
int x=50, y=60;
long pixelValue;
byte[] Data = rasterImage.GetPixelData(y, x);
pixelValue = Data[0] + Data[1] * 0x100;
Amin Dodin
Senior Support Engineer
LEAD Technologies, Inc.
![LEAD Logo LEAD Logo](https://www.leadtools.com/images/new-site-images/leadtools-logo-header.png)
LEADTOOLS Support
Imaging
Imaging SDK Questions
Pixel-by-pixel processing of 16-bit grayscale in .NET
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.