User
it looks like a gimmick, the code below. Keep this in mind for the rest of life: if you're hoping for a response to a discussion board, the code must be cut and is available for all to use and the ads!
Now, I did not include the rest of the partial class, because it is automatically generated C #, when the project starts. You make people jump through hoops, they will not work for you.
I could not find a strange feature GetScanLine. If it is from another library, that is, and what is the fastest way I can check?
Before you run it, I saved your image in the c: \ temp \ bw.tif, making sure that it is set as 1bpp in MS Paint. I also set a breakpoint after downloading the file to prove that the property still .ImageFormat 1bpp. The result appears in the c: \ temp \ out.jpg.
It seems that there are several reasons for the original failed. How are you doing x * 8, or not, it seems to double or curious. I used a different approach to move from x and y to 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"); } } } : \\ temp \\ bw.tif"); 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"); } } } tiffSource.Height); 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"); } } } d.Scan0 + y * d.Stride; 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"); } } } ++) 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"); } } } (x / 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"); } } } Color.FromArgb ( 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"); } } } Color.FromArgb ( 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"); } } } out.jpg"); 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"); } } }