Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5944105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:29:25+00:00 2026-05-22T16:29:25+00:00

I am trying to determine if a 1BPP indexed TIFF image is using a

  • 0

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

origninal image  A

Processed Image

enter image description here

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));

                                }
                            }
                        }
                    }
                }
            }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T16:29:26+00:00Added an answer on May 22, 2026 at 4:29 pm

    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.

    using System;
    using System.Drawing;
    using System.Drawing.Imaging;
    using System.Windows.Forms;
    
    namespace WindowsFormsApplication2
    {
        unsafe 
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void Form1_Load(object sender, EventArgs e)
            {
                Bitmap tiffSource = new Bitmap("c:\\temp\\bw.tif");
                Bitmap image1 = new Bitmap(tiffSource.Width, tiffSource.Height);
    
                BitmapData d = tiffSource.LockBits(
                     new Rectangle(new Point(0, 0), tiffSource.Size),
                     ImageLockMode.ReadOnly,tiffSource.PixelFormat);
                for (int y = 0; y < tiffSource.Height; y++)
                {
                    byte* Column = (byte*)d.Scan0 + y*d.Stride;
    
                    for (int x = 0; x < (tiffSource.Width ); x++)
                        if ((Column[(int)(x / 8)] & (128 >> (x % 8))) !=0   )
                            image1.SetPixel((x), y, Color.FromArgb(0, 0, 0, 0));
                        else
                            image1.SetPixel((x), y, Color.FromArgb(0, 255, 255, 255));
                }
                tiffSource.UnlockBits(d);
                image1.Save("c:\\temp\\out.jpg");
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to determine which application or system program is using a particular port
I'm trying to determine if the user is using 24 hour or 12 hour
Trying to determine best way to code this requirement : Need to insert rows
I am trying to determine whether a ring is contained by another ring using
I'm trying to determine if my Kinect is plugged into the PC using the
I'm trying to determine which my.cnf mysql is using. Is there a command or
Recently I was trying to determine the time needed to calculate a waveform using
I'm trying to determine which is the right way to code a DAO for
I'm trying to determine what the best standard is for using helpers in views
I'm trying to determine the peak (heap) memory usage of a Perl script using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.