基于位图输入文件,显示另外三个位图图像,分别显示三种颜色分量

本文关键字:显示 位图 图像 三种 分量 颜色 三个 于位图 输入 文件 | 更新日期: 2023-09-27 18:37:06

嗯,我有C#的基本知识,但我有中等的C ++技能。有人让我在分配时帮助他们,在我咨询互联网后,我以为我设法做到了,但我不知道为什么它不起作用。分配:编写一个程序,根据位图文件输入生成三个位图文件,分别显示三个颜色分量。代码 :

    private void GetPixel_1(PaintEventArgs e)
    {

        Bitmap bmp = new Bitmap(pictureBox1.Image);
        Bitmap bmp1 = new Bitmap(pictureBox2.Image);
        Bitmap bmp2 = new Bitmap(pictureBox3.Image);
        Bitmap bmp3 = new Bitmap(pictureBox4.Image);
        Color color = new Color();
        for (int ii = 0; ii < 200; ii++)
        {
            for (int jj = 0; jj < 200; jj++)
            {
                color = bmp.GetPixel(ii, jj);
                bmp1.SetPixel(ii, jj, Color.FromArgb(color.R, 0, 0));
                bmp2.SetPixel(ii, jj, Color.FromArgb(0, 0,color.B));
                bmp3.SetPixel(ii, jj, Color.FromArgb(0, color.G, 0));
            }
        }
        pictureBox2.Image = bmp1;
        pictureBox3.Image = bmp2;
        pictureBox4.Image = bmp3;

    }

我知道这对大多数人来说可能看起来很基本,但如果有人能帮助我,我仍然会不胜感激。

基于位图输入文件,显示另外三个位图图像,分别显示三种颜色分量

class Program
{
    static void Main(string[] args)
    {
        Bitmap bitmap = new Bitmap("Image.bmp");
        Bitmap red = new Bitmap(bitmap.Width, bitmap.Height);
        Bitmap blue = new Bitmap(bitmap.Width, bitmap.Height);
        Bitmap green = new Bitmap(bitmap.Width, bitmap.Height);
        for (int x = 0; x < bitmap.Width; x++)
        {
            for (int y = 0; y < bitmap.Height; y++)
            {
                Color c = bitmap.GetPixel(x, y);
                red.SetPixel(x, y, Color.FromArgb(c.R, 0, 0));
                blue.SetPixel(x, y, Color.FromArgb(0, 0, c.B));
                green.SetPixel(x, y, Color.FromArgb(0, c.G, 0));
            }
        }
        // - Don't forget to save, until now we're only messing with the loaded memory of the bitmap.
        red.Save("Red.bmp");
        blue.Save("Blue.bmp");
        green.Save("Green.bmp");
    }        
}