24位图像到1位图像 [英] 24bit image to 1bit image

查看:152
本文介绍了24位图像到1位图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码:

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


错误显示"+ =操作数无法应用于类型"和"系统"。 IntPtr和int""
$


如何解决这个问题?

the error shows "+= operand can't be applied on type ""System.IntPtr and int""

how can I solve this problem?

推荐答案

Castorix有更好的整体解决方案,但您问题的直接答案是

Castorix has a better overall solution, but the immediate answer to your question is

  &NBSP;   scanLine = IntPtr.Add(scanLine,inputData.Stride);

     scanLine = IntPtr.Add( scanLine, inputData.Stride );


这篇关于24位图像到1位图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆