C#如何使R.G.B的价值远远提高? [英] C# How to get value R.G.B far?

查看:86
本文介绍了C#如何使R.G.B的价值远远提高?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private void pictureBox1_MouseMove(object sender, MouseEventArgs e) 
{
        if (pictureBox1.Image != null) 
        { 
 
 
          Bitmap b = new Bitmap(pictureBox1.Image); 
          if (e.X >= 0 && e.X <= b.Width && e.Y >= 0 && e.Y <= b.Height) 
          { 
              Color c = b.GetPixel(e.X, e.Y); 
              mouseCOL.Text = "R : " + c.R.ToString() + " G : " + c.G.ToString() 
                          + " B : " + c.B.ToString(); 
          } 
 
 
            /*Bitmap b = new Bitmap(pictureBox1.Image); 
            Color c = b.GetPixel(e.X, e.Y); 
 
            mouseCOL.Text = "R : " + c.R.ToString() + " G : " + c.G.ToString() 
            + " B : " + c.B.ToString();*/ 
 
 
        } 
        else 
        { 
 
        } 
    } 



eXeY当您只是无法弄清楚如何处理异常时,似乎出现了乘员组宽度比图像大小相应的值.Mouse Move事件将他放在图片框中

转到参数的任何部分都必须为正数,并且应小于Width.

参数名称:x

Tteuneyo出现错误

pictuerBox的大小,准备为我们带来图片放大样式



eX, eYcorresponding values ​​for Width of the crew than the size of the image seems to occur when you just can not figure out how to handle exceptions Mouse Move event put him in a Picture Box

Go to any part of the parameter must be positive and will be less than Width.

The parameter name: x

Tteuneyo that errors

pictuerBox size and ready to bring us a picture to zoom Style

推荐答案

请,请不要这样做!
每次移动鼠标(每秒可能移动一百次或更多次),您都在创建一个与现有位图相同的新位图!而且您不会对其进行处理,因此它一直在闲逛,直到垃圾收集器出现为止.

我想不出一种效率较低的方法来做到这一点!

首先,如果创建位图,则负责显式地或通过在using 块中创建位图来对其进行处置:
Please, please, do not do that!
Every time you move the mouse (and that can be a hundred or more times a second) you are creating a new bitmap the same as the existing one! And you don''t dispose of it, so it is hanging around until the Garbage Collector comes along to get rid of it.

I cannot think of a single less efficient way to do that!

Fiurstly, if you create a bitmap, you are responbsible for Disposing it, either explicitly, or by creating it in a using block:
using(Bitmap b = new Bitmap(pictureBox1.Image))
{
   if (e.X >= 0 && e.X <= b.Width && e.Y >= 0 && e.Y <= b.Height)
   {
       Color c = b.GetPixel(e.X, e.Y);
       mouseCOL.Text = "R : " + c.R.ToString() + " G : " + c.G.ToString()
                   + " B : " + c.B.ToString();
   }


     /*Bitmap b = new Bitmap(pictureBox1.Image);
     Color c = b.GetPixel(e.X, e.Y);

     mouseCOL.Text = "R : " + c.R.ToString() + " G : " + c.G.ToString()
     + " B : " + c.B.ToString();*/
 }

但是一个更好的主意是根本不创建一个新的:

But a better idea is not to create a new one at all:

Bitmap b = (Bitmap) pictureBox1.Image;
if (e.X >= 0 && e.X <= b.Width && e.Y >= 0 && e.Y <= b.Height)
{
    Color c = b.GetPixel(e.X, e.Y);
    mouseCOL.Text = "R : " + c.R.ToString() + " G : " + c.G.ToString()
                + " B : " + c.B.ToString();
}


  /*Bitmap b = new Bitmap(pictureBox1.Image);
  Color c = b.GetPixel(e.X, e.Y);

  mouseCOL.Text = "R : " + c.R.ToString() + " G : " + c.G.ToString()
  + " B : " + c.B.ToString();*/



剩下的问题我根本听不懂-可能是语言问题,但是请尝试给我们提供实际的错误消息,并指出在哪一行得到它.



The rest of your problem I don''t understand at all - it''s probably a language thing, but please try top give us the actual error message, and indicate on which line you are getting it.


这篇关于C#如何使R.G.B的价值远远提高?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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