进行图像处理 [英] make image processing

查看:58
本文介绍了进行图像处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

我有一张黑色背景的图片,中间有一个白色正方形

我只想在图片框中打印白色方块

hello

I have a picture with a black background and in the middle a white square

I want to print white square in the picture box only
can you help me?

推荐答案

在生成时,您可以使用以下代码在图像中裁剪特定区域:

In generate you can crop a specific area in an image using the below code:

public void Crop(int xPosition, int yPosition, int width, int height)
{
    Bitmap temp = (Bitmap)_currentBitmap;
    Bitmap bmap = (Bitmap)temp.Clone();
    if (xPosition + width > _currentBitmap.Width)
                 width = _currentBitmap.Width - xPosition;
         if (yPosition + height > _currentBitmap.Height)
                 height = _currentBitmap.Height - yPosition;
         Rectangle rect = new Rectangle(xPosition, yPosition, width, height);
         _currentBitmap = (Bitmap)bmap.Clone(rect, bmap.PixelFormat);
}



然后,您可以将滤色器设置为:



Then, you can set the color filter as:

public void SetColorFilter(ColorFilterTypes colorFilterType)
{
    Bitmap temp = (Bitmap)_currentBitmap;
    Bitmap bmap = (Bitmap)temp.Clone();
    Color c;
    for (int i = 0; i < bmap.Width; i++)
    {
    for (int j = 0; j < bmap.Height; j++)
    {
                 c = bmap.GetPixel(i, j);
                  int nPixelR = 0;
                  int nPixelG = 0;
                  int nPixelB = 0;
                  if (colorFilterType == ColorFilterTypes.Red)
                  {
                          nPixelR = c.R;
                          nPixelG = c.G - 255;
                              nPixelB = c.B - 255;
                  }
                  else if (colorFilterType == ColorFilterTypes.Green)
                  {
                          nPixelR = c.R - 255;
                     nPixelG = c.G;
                            nPixelB = c.B - 255;
                  }
                  else if (colorFilterType == ColorFilterTypes.Blue)
                  {
                            nPixelR = c.R - 255;
                            nPixelG = c.G - 255;
                            nPixelB = c.B;
                  }
                  nPixelR = Math.Max(nPixelR, 0);
                  nPixelR = Math.Min(255, nPixelR);

                  nPixelG = Math.Max(nPixelG, 0);
                  nPixelG = Math.Min(255, nPixelG);

                  nPixelB = Math.Max(nPixelB, 0);
                  nPixelB = Math.Min(255, nPixelB);

                  bmap.SetPixel(i, j, Color.FromArgb((byte)nPixelR,
					(byte)nPixelG, (byte)nPixelB));
            }
        }
        _currentBitmap = (Bitmap)bmap.Clone();
}


这篇关于进行图像处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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