【问题标题】:PictureBox Drawed image colors to arrayPictureBox 将图像颜色绘制到数组中
【发布时间】:2012-01-28 14:54:31
【问题描述】:

我得到了 400x300 的图片框,它有一个“mousedown”事件,它用一些红色填充的椭圆代替了鼠标点击。我现在遇到的问题是,我想将每个像素的颜色放入一个数组中。我在那里只有 3 种颜色,黑色(RGB 中的 0,0,0)、红色(255,0,0)和 while(255,255,255)。 问题是,我如何运行整个图片框并获取颜色值?我没有可以使用的“getPixel”。我尝试将图片框的图像传递给位图

Bitmap zdjecie_box = new Bitmap(pictureBox1.Image)

但它说图像正确为空(null),所以我猜绘制的图像没有存储在 .image 中,而是存储在其他地方。我想要那个,因为我会使用 zdjecie_box.GetPixel(i, j).R; 并将其保存到数组中。

有什么想法吗?

【问题讨论】:

    标签: c# visual-studio visual-studio-2010 drawing picturebox


    【解决方案1】:

    如果您定义自己的图像并将其设置在绘图事件中,则可以轻松访问它。例如

     Bitmap _b;
     private void Form1_Paint(object sender, PaintEventArgs e)
     {
        _b = new Bitmap(pictureBox1.Width, pictureBox1.Height);
        Graphics g = Graphics.FromImage(_b);
        g.DrawEllipse(Pens.Black,new Rectangle(0,0,25,25));
        pictureBox1.Image = _b;
     }
     ...
     private void ParseImage()
     {
        for (int y = 0; y < _b.Height; y++)
        {
           for (int x = 0; x < _b.Width; x++)
           {
              Color c = _b.GetPixel(x, y);
           }
         }
      }
    

    【讨论】:

    • 我想我现在爱你了。谢谢你:)
    猜你喜欢
    • 2018-03-17
    • 2023-03-11
    • 1970-01-01
    • 1970-01-01
    • 2020-09-07
    • 1970-01-01
    • 2020-06-17
    • 2021-10-21
    • 1970-01-01
    相关资源
    最近更新 更多