none
24bit image to 1bit image RRS feed

  • Question

  • Here is my code:

    public static Bitmap ConvertTo1Bit(Bitmap input)
            {
                var masks = new byte[] { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 };
                var output = new Bitmap(input.Width, input.Height, PixelFormat.Format1bppIndexed);
                var data = new sbyte[input.Width, input.Height];
                var inputData = input.LockBits(new Rectangle(0, 0, input.Width, input.Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
                try
                {
                    var scanLine = inputData.Scan0;
                    var line = new byte[inputData.Stride];
                    for (var y = 0; y < inputData.Height; y++, scanLine += inputData.Stride)
                    {
                        Marshal.Copy(scanLine, line, 0, line.Length);
                        for (var x = 0; x < input.Width; x++)
                        {
                            data[x, y] = (sbyte)(64 * (GetGreyLevel(line[x * 3 + 2], line[x * 3 + 1], line[x * 3 + 0]) - 0.5));
                        }
                    }
                }
                finally
                {
                    input.UnlockBits(inputData);
                }
    I'm facing problem in  "
    scanLine += inputData.Stride
    the error shows "+= operand can't be applied on type ""System.IntPtr and int""

    how can I solve this problem?

    Sunday, May 27, 2018 9:25 AM

All replies