C#彩色图片灰度化算法实例
- 作者: 想到你我就硬了唉
- 来源: 51数据库
- 2021-11-06
本文实例讲述了c#彩色图片灰度化实现方法。分享给大家供大家参考。具体方法如下:
主要功能代码如下:
{
//create a blank bitmap the same size as original
bitmap newbitmap = new bitmap(original.width, original.height);
//get a graphics object from the new image
graphics g = graphics.fromimage(newbitmap);
//create the grayscale colormatrix
system.drawing.imaging.colormatrix colormatrix = new system.drawing.imaging.colormatrix(
new float[][]
{
new float[] {.3f, .3f, .3f, 0, 0},
new float[] {.59f, .59f, .59f, 0, 0},
new float[] {.11f, .11f, .11f, 0, 0},
new float[] {0, 0, 0, 1, 0},
new float[] {0, 0, 0, 0, 1}
});
//create some image attributes
system.drawing.imaging.imageattributes attributes = new system.drawing.imaging.imageattributes();
//set the color matrix attribute
attributes.setcolormatrix(colormatrix);
//draw the original image on the new image
//using the grayscale color matrix
g.drawimage(original, new rectangle(0, 0, original.width, original.height), 0, 0, original.width, original.height, graphicsunit.pixel, attributes);
//dispose the graphics object
g.dispose();
return newbitmap;
}
希望本文所述对大家的c#程序设计有所帮助。
- C#通过fleck实现wss协议的WebSocket多人Web实时聊天(附源码)
- 团队城市未满足要求:MSBuildTools12.0_x86_Path 存在
- 使用 MSBuild.exe 在发布模式下构建 C# 解决方案
- 当我发布 Web 应用程序时,AfterPublish 脚本不运行
- 构建时 T4 转换的产品仅在下一个构建中使用
- ASP.NET Core Application (.NET Framework) for Windows x64 only error in project.assets.json
- 新的 .csproj 格式 - 如何将整个目录指定为“链接文件"到子目录?
- 如何将条件编译符号(DefineConstants)传递给 msbuild
- MSBuild 支持 Visual Studio 2017 RTM 中的 T4 模板
- NuGet 包还原找不到包,没有源