基本信息
源码名称:winForm图片特效实例
源码大小:0.03M
文件格式:.txt
开发语言:C#
更新时间:2014-10-30
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 1 元 
   源码介绍

实现winform图片特效


public class ImageClass
    {
        /// <summary>
        /// 将图片转换成黑白色效果
        /// </summary>
        /// <param name="bmp">Bitmap 对象</param>
        /// <param name="picBox">PictureBox 对象</param>
        public static void HeiBaiSeImage(Bitmap bmp, PictureBox picBox)
        {
            //以黑白效果显示图像
            Bitmap oldBitmap;
            Bitmap newBitmap=null;
            try
            {
                int Height = bmp.Height;
                int Width = bmp.Width;
                newBitmap = new Bitmap(Width, Height);
                oldBitmap = bmp;
                Color pixel;
                for (int x = 0; x < Width; x )
                    for (int y = 0; y < Height; y )
                    {
                        pixel = oldBitmap.GetPixel(x, y);
                        int r, g, b, Result = 0;
                        r = pixel.R;
                        g = pixel.G;
                        b = pixel.B;
                        //实例程序以加权平均值法产生黑白图像
                        int iType = 2;
                        switch (iType)
                        {
                            case 0://平均值法
                                Result = ((r g b) / 3);
                                break;
                            case 1://最大值法
                                Result = r > g ? r : g;
                                Result = Result > b ? Result : b;
                                break;
                            case 2://加权平均值法
                                Result = ((int)(0.7 * r) (int)(0.2 * g) (int)(0.1 * b));
                                break;
                        }
                        newBitmap.SetPixel(x, y, Color.FromArgb(Result, Result, Result));
                    }
                
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "信息提示");
            }
            picBox.Image = newBitmap;
        }