简体   繁体   English

使用C#修改位图图像中像素的颜色时出错

[英]Error while modifying the color of pixels in a bitmap image with c#

I have this code in which I try to modify the color of the pixel (x,y). 我有这段代码尝试修改像素(x,y)的颜色。 I want to just get the Color given by Color.White - the color of the pixel (x,y) 我只想获取Color.White给定的Color-像素(x,y)的颜色

  Bitmap  mPlan;
  for (int x=0; x < mPlanWidth; x++)
            {
                for (int y=0; y < mPlanHeight; y++)
                {
                    if (mPlan.GetPixel(x, y) == Color.White)
                     mPlan.SetPixel(x, y,  Color.White - mPlan.GetPixel(x, y));
                }

            }

But I have an error in the level of Color.White - mPlan.GetPixel(x, y) which tells me impossible conversion of int to Android.Graphics.Color 但是我在Color.White的级别上有一个错误-mPlan.GetPixel(x,y)这告诉我不可能将int转换为Android.Graphics.Color

I Tried to convert all the colors to int using the Argb 我试图使用Argb将所有颜色转换为int

   mPlan.SetPixel(x, y, System.Drawing.Color.FromArgb(System.Drawing.Color.White.ToArgb()- mFloorPlan.GetPixel(x, y))   );

But the methods TpArgb are given only by the assembly System.Drawing and SetPixel take as third parametre a color of Android.Graphics So I have this conflict of types. 但是TpArgb方法仅由程序集System.Drawing和SetPixel给出,将Android.Graphics的颜色作为第三个参数,所以我遇到了类型冲突。

Bitmap bc;
Color color = new Color();
color.R = Color.White.R - bc.GetPixel(x, y).R;
color.G = Color.White.G - bc.GetPixel(x, y).G;
color.B = Color.White.B - bc.GetPixel(x, y).B;
bc.SetPixel(x, y, color);

Generate new color by setting the RGB value of the new color. 通过设置新颜色的RGB值来生成新颜色。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM