Upload pictures and turn into a gray picture

This is to be generated offline when previously written user avatar upload pictures do webim, namely black and white picture of the code

Function code is as follows:

 

05233544_o2Dq.gif 05233544_wgFB.gif Code
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();
        }

Reproduced in: https: //my.oschina.net/secyaher/blog/274227

Guess you like

Origin blog.csdn.net/weixin_34235105/article/details/91966877