Image 颜色分量 、获取略缩图

ColorMatrix

灰色,图片去色
r = 像素点的红色分量0.299 + 像素点的绿色分量0.587 + 像素点的蓝色分量0.114

 ColorMatrix _matrix = new ColorMatrix(new float[][]{
                new float[]{0.299f,0.299f,0.299f,0.299f,0.299f},
                new float[]{0.587f,0.587f,0.587f,0.587f,0.587f},
                new float[]{0.114f,0.114f,0.114f,0.114f,0.114f},
                new float[]{0,0,0,1,0},
                new float[]{0,0,0,0,1}

 ///运用

 ///sourimg 源图片,rectSize 保存图片大小

 private Image GetImage(string sourimg,Rectangle rectSize)
        {
            ColorMatrix colorMatr =  new ColorMatrix(new float[][]{
                new float[]{0.299f,0.299f,0.299f,0.299f,0.299f},
                new float[]{0.587f,0.587f,0.587f,0.587f,0.587f},
                new float[]{0.114f,0.114f,0.114f,0.114f,0.114f},
                new float[]{0,0,0,1,0},
                new float[]{0,0,0,0,1};

       

            Image imageDemo = Image.FromFile(sourimg, true);

            Bitmap bitmap = new Bitmap(rectSize.Width, rectSize.Height);
            Graphics g= Graphics.FromImage(bitmap);
            ImageAttributes imagAtt = new ImageAttributes();
            imagAtt.SetColorMatrix(colorMatr);
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;
            g.SmoothingMode = SmoothingMode.HighSpeed;
            g.DrawImage(imageDemo, rectSize, 0, 0, imageDemo.Width, imageDemo.Height, GraphicsUnit.Pixel, imagAtt);

            return bitmap;
        }

------------------------------------------------------------分界线-----------------------------------------------

      // 产生缩略图
        private void Thumb(string imgPath, string thumbPath)
        {
            System.Drawing.Image.GetThumbnailImageAbort myCallback = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);
            System.Drawing.Image img = System.Drawing.Image.FromFile(imgPath); // 通过文件构造
            //生成缩略图
       
            System.Drawing.Image myThumbnail = img.GetThumbnailImage(100, 50, myCallback, IntPtr.Zero);
            myThumbnail.Save(thumbPath); // 保存缩略图
        }
        // 取消操作回调
        private bool ThumbnailCallback()
        {
            return false;
        }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值