博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
图片上传并转成灰白图片
阅读量:7252 次
发布时间:2019-06-29

本文共 1301 字,大约阅读时间需要 4 分钟。

这是以前做webim时写的上传用户头像时要生成离线状态的图片,即黑白图片的代码

函数代码如下:

 

ExpandedBlockStart.gif
public void MakeSmallImg(string fileName, string saveImg, Rectangle OutputArea,bool toBlackWhite)
        {
            System.Drawing.Image ImageDemo 
= System.Drawing.Image.FromFile(fileName, true);
            System.Drawing.Bitmap OutputImage 
= new System.Drawing.Bitmap(OutputArea.Width, OutputArea.Height);
            System.Drawing.Graphics MapGraphy 
= System.Drawing.Graphics.FromImage(OutputImage);
            MapGraphy.InterpolationMode 
= System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
            MapGraphy.SmoothingMode 
= System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            MapGraphy.Clear(System.Drawing.Color.White);
            
if (toBlackWhite)
            {
                ColorMatrix _matrix 
= new ColorMatrix();
                _matrix[
00= 1 / 3f;
                _matrix[
01= 1 / 3f;
                _matrix[
02= 1 / 3f;
                _matrix[
10= 1 / 3f;
                _matrix[
11= 1 / 3f;
                _matrix[
12= 1 / 3f;
                _matrix[
20= 1 / 3f;
                _matrix[
21= 1 / 3f;
                _matrix[
22= 1 / 3f;
                ImageAttributes _attributes 
= new ImageAttributes();
                _attributes.SetColorMatrix(_matrix);
                MapGraphy.DrawImage(ImageDemo, OutputArea, 
00, ImageDemo.Width, ImageDemo.Height, GraphicsUnit.Pixel, _attributes);
            }
            
else
            {
                MapGraphy.DrawImage(ImageDemo, OutputArea);
            }
            OutputImage.Save(saveImg, System.Drawing.Imaging.ImageFormat.Bmp);
            MapGraphy.Dispose();
            OutputImage.Dispose();
            ImageDemo.Dispose();
        }
你可能感兴趣的文章
实现网站图片瀑布流重点记录
查看>>
软件测试全职以及兼职平台以及薪酬报价
查看>>
Javascript:日期排班功能实现
查看>>
git push之后回滚(撤销)代码
查看>>
数组,字符串互相转化
查看>>
linux centos下配置静态ip地址
查看>>
Maven学习总结(三)——使用Maven构建项目
查看>>
Computer Vision & MultiMedia 相关国际会议汇总
查看>>
vs2008在win7系统中安装不问题
查看>>
HDU-1520 Anniversary party
查看>>
springmvc web.xml配置之 -- ContextLoaderListener
查看>>
java_数组作缓存池的不可变类实例
查看>>
webservice主流框架Axis、Axis2、XFire、CXF的比较
查看>>
mybatis输出SQL格式化
查看>>
lambda
查看>>
Master Nginx(3) - Using the Mail Module
查看>>
4、jeecg 笔记之 自定义显示按钮 (exp 属性)
查看>>
Js 手风琴效果
查看>>
QTP10补丁汇总
查看>>
支持常见数据库差异对照说明
查看>>