图像转换为灰度不能在32位机器上工作

本文关键字:32位 机器 工作 不能 转换 灰度 图像 | 更新日期: 2023-09-27 17:50:36

我有一个windows服务,可以将图像转换为黑色&白色和深褐色的缩略图。我的电脑是64位的Windows 7。我安装服务的服务器是32位的Windows server 2003。

代码在我的机器以及其他64位机器上工作完美,但在服务器上它不能将图像转换为黑色&白色和棕褐色。

我已经为我的项目设置了平台目标为x86。

我使用的是vs2008框架3.5和c#。

代码如下:

    private Bitmap ConvertToBlackAndWhite(Bitmap loImage)
    {
        int height = loImage.Height;
        int width = loImage.Width;
        for (int yCoordinate = 0; yCoordinate < height; yCoordinate++)
        {
            for (int xCoordinate = 0; xCoordinate < width; xCoordinate++)
            {
                //Get the pixel that's at our current coordinate.
                Color color = loImage.GetPixel(xCoordinate, yCoordinate);
                //Calculate the gray to use for this pixel.
                int grayColor = (int)(color.R * 0.3 + color.G * 0.59 + color.B * 0.11);
                //Set the pixel to the new gray color.
                loImage.SetPixel(xCoordinate, yCoordinate, Color.FromArgb(grayColor, grayColor, grayColor));
            }
        }
        return loImage;
    }

我一直试图谷歌它相当一段时间,并没有能够找到任何东西到目前为止。

在我秃顶之前所有的帮助都是非常感激的:)。

图像转换为灰度不能在32位机器上工作

我已经能够解决这个问题了。如果我处理缩略图而不是图像本身,问题就解决了。谢谢@mh帮我指出来