近来研究了一下GDI+绘图的基本操作,也学到了不少东西

绘制灰色图片:

        System.Drawing.Bitmap bm = new System.Drawing.Bitmap

(this.pictureBox1.Image.Width,

this.pictureBox1.Image.Height,

System.Drawing.Imaging.PixelFormat.Format24bppRgb);

        System.Drawing.Bitmap bmOriginal = (Bitmap)this.pictureBox1.Image;

        for(int y=0;y<bmOriginal.Height;y++)

        {

                for(int x=0;x<bmOriginal.Width;x++)

                {

                        Color c=bmOriginal.GetPixel(x,y);

                        int red,green,blue;

                        red = (int)(c.R*0.3 + c.G*0.59+ c.B*0.11);

                        green = (int)(c.R*0.3 + c.G*0.59+ c.B*0.11);

                        blue = (int)(c.R*0.3 + c.G*0.59+ c.B*0.11);

                        bm.SetPixel(x,y,Color.FromArgb(red,green,blue));

                }

        }

this.pictureBox1.Image = bm;



绘制反色图片:


       
System.Drawing.Bitmap bm = new System.Drawing.Bitmap

(this.pictureBox1.Image.Width,

this.pictureBox1.Image.Height,

System.Drawing.Imaging.PixelFormat.Format24bppRgb);

        System.Drawing.Bitmap bmOriginal = (Bitmap)this.pictureBox1.Image;

        for(int y=0;y<bmOriginal.Height;y++)

        {

                for(int x=0;x<bmOriginal.Width;x++)

                {

                    Color c=bmOriginal.GetPixel(x,y);

                    int red,green,blue;    

      red = (int)(255-c.R);

                    green = (int)(255-c.G);

      blue = (int)(255-c.B);        
   }            
                                                

   bm.SetPixel(x,y,Color.FromArgb(red,green,blue));

               

        }


        this
.pictureBox1.Image = bm;


在使用
GraphicsDrawImage方法时,graphics使用Graphics.FromImage(Image)获得,既可绘制Image.

 

还有许多技巧,具体参考:http://www.bobpowell.net/faqmain.htmcodeproject上的一些文章和代码

 

相关文章:

  • 2022-12-23
  • 2021-09-13
  • 2021-08-06
  • 2021-11-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-24
猜你喜欢
  • 2022-02-15
  • 2021-06-12
  • 2022-02-02
  • 2021-07-30
  • 2021-11-17
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案