WPF:图像处理(二)灰度化
[csharp]
文件名称:Gray.cs
开发环境:
Visual Studio V2010
.NET Framework 4 Client Profile
版本历史:
V1.0 2012年04月16日
图像灰度化
------------------------------------------------------------ */
using System;
using System.Windows.Media;
using System.Windows.Media.Imaging;
namespace Splash.Imaging
{
/// <summary>
/// 图像处理:灰度化
/// </summary>
public static class Gray
{
/// <summary>
/// 将位图转换为彩色数组
/// </summary>
/// <param name="bitmap">原始位图</param>
/// <returns>彩色数组</returns>
/// <remarks>
/// 1.扩展方法
/// 2.忽视Alpha通道
/// </remarks>
public static Color[,] ToColorArray(this BitmapSource bitmap)
{ // 将像素格式统一到Bgr32,并提取图像数据
Int32 PixelHeight = bitmap.PixelHeight; // 图像高度
Int32 PixelWidth = bitmap.PixelWidth; // 图像宽度
Int32 Stride = PixelWidth << 2; // 扫描行跨距
Byte[] Pixels = new Byte[PixelHeight * Stride];
if (bitmap.Format == PixelFormats.Bgr32 || bitmap.Format == PixelFormats.Bgra32)
{ // 拷贝像素数据
bitmap.CopyPixels(Pixels, Stride, 0);
}
else
{ // 先进行像素格式转换,再拷贝像素数据
相关新闻>>
- 发表评论
-
- 最新评论 进入详细评论页>>
今日头条
更多>>您可能感兴趣的文章
- asp.net js模拟Button点击事件
- winform下通过webclient使用非流方式上传(post)数据和
- 教你如何来恢复一个丢失的数据文件
- 微软ASP.NET站点部署指南(11):部署SQL Server数据
- ASP.NET数据格式的Format--DataFormatString
- Pro ASP.NET MVC 3 Framework学习笔记之九
- asp.net 六大内置对象(2)
- Asp.net MVC源码分析--Model Validation(Client端)实现(2)
- MVC中一个表单实现多个提交按钮(一个action搞定
- 谈.Net委托与线程——创建无阻塞的异步调用(一