createimg.aspx.cs
来自「.net GDI+ 图片生成黑白效果」· CS 代码 · 共 37 行
CS
37 行
using System;
using System.Drawing;
using System.Drawing.Imaging;
public partial class createimg : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public void Oldimg(string spath, string npath)
{
Bitmap currentBitmap = new Bitmap(spath);
Graphics g = Graphics.FromImage(currentBitmap);
#region 调整颜色矩阵
ImageAttributes ia = new ImageAttributes();
//黑白
float[][] colorMatrix = {
new float[] {0.3F, 0.3F, 0.3F, 0, 0},
new float[] {0.59F, 0.59F, 0.59F, 0, 0},
new float[] {0.11F, 0.11F, 0.11F, 0, 0},
new float[] {0, 0, 0, 1, 0},
new float[] {0, 0, 0, 0, 1}};
ColorMatrix cm = new ColorMatrix(colorMatrix);
ia.SetColorMatrix(cm, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
g.DrawImage(currentBitmap, new Rectangle(0, 0, currentBitmap.Width, currentBitmap.Height), 0, 0, currentBitmap.Width, currentBitmap.Height, GraphicsUnit.Pixel, ia);
#endregion 调整颜色矩阵
//浮雕
//currentBitmap = GetImageLine(currentBitmap);
currentBitmap.Save(npath, ImageFormat.Jpeg);
g.Dispose();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?