I am trying to determine if a 1BPP indexed TIFF image is using a white pixel or black pixel. To check if my code was correct , I made the application draw the same image it proccessed onto a new image. This is when I noticed some problems and I have beem beating my head trying to figure it out.
I am pretty sure it has something to do with my bitwise check!
origninal image

Processed Image

Test project can be downloaded at http://www.unclickable.net/code/tiffTest.zip
unsafe
{
//flipStartPoint
int y;
for (y = 0; y < tiffSource.Height; y++)
{
var Column = (byte*)tiffSource.GetScanlinePointer(y);
int x;
for (x = 0; x < (tiffSource.Width / 8); x++)
{
int xm = x * 8;
byte b = Column[xm];
if (b > 0)
{
for (int Z = 0; Z < 8; Z++)
{
if (((b & (128 >> Z)) != 0))
{
if (lowisWhite)
{
image1.SetPixel((xm + Z), y, Color.FromArgb(0, 255, 255,255));
}
}
else
{
if (!lowisWhite)
{
image1.SetPixel((xm + Z), y, Color.FromArgb(0, 255,255, 255));
}
}
}
}
else
{
if (!lowisWhite)
{
for (int Z = 0; Z < 8; Z++)
{
image1.SetPixel((xm + Z), y, Color.FromArgb(0, 255, 255, 255));
}
}
}
}
}
}
User,
this seems to do the trick, the code below. Remember this for the rest of your life: if you hope any response from a discussion board, the code should be cuttable and pastable with all using’s and declarations included!
Now I didn’t include the rest of the partial class because it is automatically generated by c# when you start a project. You make people jump thru hoops they are not going to work for you.
I could not find the strange GetScanLine function. If is from another library, what is that and what’s the quickest way I could test with it?
Before running this I saved your image in c:\temp\bw.tif, making sure to set it as 1bpp in MS Paint. I also set a breakpoint after the load of the file to prove that the .ImageFormat property was 1bpp. Result appears in c:\temp\out.jpg.
Looks like there are several reasons why the original failed. The way you are doing x*8, or not, seems doubled or curious. I took a different approach to go straight from x and y to the pixel.