private void mirror_Click(object sender, EventArgs e)
{
if (curBitmap!=null)
{
mirror mirForm = new mirror();
if (mirForm.ShowDialog()==DialogResult.OK)
{
Rectangle rect = new Rectangle(, , curBitmap.Width, curBitmap.Height);
BitmapData bmpData = curBitmap.LockBits(rect, ImageLockMode.ReadWrite, curBitmap.PixelFormat);
IntPtr ptr = bmpData.Scan0;
int bytes = ;
////判断是灰度色图像还是彩色图像,给相应的大小
if (curBitmap.PixelFormat==PixelFormat.Format8bppIndexed)
{
bytes= curBitmap.Width * curBitmap.Height;
}
else if (curBitmap.PixelFormat == PixelFormat.Format24bppRgb)
{
bytes = curBitmap.Width * curBitmap.Height * ;
}
byte[] pixelValues = new byte[bytes];
Marshal.Copy(ptr, pixelValues, , bytes); //水平中轴
int halfWidth = curBitmap.Width / ;
//垂直中轴
int halfHeight = curBitmap.Height / ;
byte temp;
byte temp1;
byte temp2;
byte temp3;
if (curBitmap.PixelFormat == PixelFormat.Format8bppIndexed)
{
if (mirForm.GetMirror)
{
for (int i = ; i < curBitmap.Height; i++)
for (int j = ; j < halfWidth; j++)
{
temp = pixelValues[i * curBitmap.Width + j];
pixelValues[i * curBitmap.Width + j] = pixelValues[(i + ) * curBitmap.Width - j - ];
pixelValues[(i + ) * curBitmap.Width - j - ] = temp;
}
}
else
{
for (int j = ; j < curBitmap.Width; j++)
{
for (int i = ; i < halfHeight; i++)
{
temp = pixelValues[i * curBitmap.Width + j];
pixelValues[i * curBitmap.Width + j] = pixelValues[(curBitmap.Height - i - ) * curBitmap.Width + j];
pixelValues[(curBitmap.Height - i - ) * curBitmap.Width + j] = temp;
}
}
}
}
else if (curBitmap.PixelFormat == PixelFormat.Format24bppRgb)
{
if (mirForm.GetMirror)
{
//水平镜像处理
for (int i = ; i < curBitmap.Height; i++)
{
//每个像素的三个字节在水平镜像时顺序不能变,所以这个方法不能用
//for (int j = 0; j < halfWidth; j++)
//{
// //以水平中轴线为对称轴,两边像素值交换
// temp = pixelValues[i * curBitmap.Width * 3 + j * 3];
// pixelValues[i * curBitmap.Width * 3 + j * 3] = pixelValues[(i + 1) * curBitmap.Width * 3 - 1 - j * 3];
// pixelValues[(i + 1) * curBitmap.Width * 3 - 1 - j * 3] = temp;
//}
for (int j = ; j < halfWidth; j++)
{//每三个字节组成一个像素,顺序不能乱
temp = pixelValues[ + i * curBitmap.Width * + j * ];
temp1 = pixelValues[ + i * curBitmap.Width * + j * ];
temp2 = pixelValues[ + i * curBitmap.Width * + j * ];
pixelValues[ + i * curBitmap.Width * + j * ] = pixelValues[ + (i + ) * curBitmap.Width * - (j + ) * ];
pixelValues[ + i * curBitmap.Width * + j * ] = pixelValues[ + (i + ) * curBitmap.Width * - (j + ) * ];
pixelValues[ + i * curBitmap.Width * + j * ] = pixelValues[ + (i + ) * curBitmap.Width * - (j + ) * ];
pixelValues[ + (i + ) * curBitmap.Width * - (j + ) * ] = temp;
pixelValues[ + (i + ) * curBitmap.Width * - (j + ) * ] = temp1;
pixelValues[ + (i + ) * curBitmap.Width * - (j + ) * ] = temp2;
}
}
}
else
{
//垂直镜像处理
for (int i = ; i < curBitmap.Width * ; i++)
{
for (int j = ; j < halfHeight; j++)
{
//以垂直中轴线为对称轴。两边像素值互换
temp = pixelValues[j * curBitmap.Width * + i];
pixelValues[j * curBitmap.Width * + i] = pixelValues[(curBitmap.Height - j - ) * curBitmap.Width * + i];
pixelValues[(curBitmap.Height - j - ) * curBitmap.Width * + i] = temp;
}
}
}
} Marshal.Copy(pixelValues, , ptr, bytes);
curBitmap.UnlockBits(bmpData);
}
Invalidate();
}
}

原图:

水平镜像:

垂直镜像:

c#数字图像处理(九)图像镜像的更多相关文章

  1. Win8 Metro(C#) 数字图像处理--1 图像打开,保存

    原文:Win8 Metro(C#) 数字图像处理--1 图像打开,保存 作为本专栏的第一篇,必不可少的需要介绍一下图像的打开与保存,一便大家后面DEMO的制作.   Win8Metro编程中,图像相关 ...

  2. Win8 Metro(C#)数字图像处理--4图像颜色空间描述

    原文:Win8 Metro(C#)数字图像处理--4图像颜色空间描述  图像颜色空间是图像颜色集合的数学表示,本小节将针对几种常见颜色空间做个简单介绍. /// <summary> / ...

  3. 数字图像处理,图像锐化算法的C++实现

    http://blog.csdn.net/ebowtang/article/details/38961399 之前一段我们提到的算法都是和平滑有关, 经过平滑算法之后, 图像锐度降低, 降低到一定程度 ...

  4. 数字图像处理:图像的灰度变换(Matlab实现)

    (1)线性变换:通过建立灰度映射来调整源图像的灰度. k>1增强图像的对比度:k=1调节图像亮度,通过改变d值达到调节亮度目的:0 i = imread('theatre.jpg');i = i ...

  5. 数字图像处理界标准图像 Lena 后面的故事

    熟悉图像处理或者压缩的工程师.研究人员和学生,经常在他们的实验或者项目任务里使用"Lenna"或者"Lena"的图像.Lenna 图像已经成为被广泛使用的测试图 ...

  6. 【数字图像处理】六.MFC空间几何变换之图像平移、镜像、旋转、缩放具体解释

    本文主要讲述基于VC++6.0 MFC图像处理的应用知识,主要结合自己大三所学课程<数字图像处理>及课件进行解说,主要通过MFC单文档视图实现显示BMP图片空间几何变换.包含图像平移.图形 ...

  7. Win8Metro(C#)数字图像处理--2.19图像水平镜像

    原文:Win8Metro(C#)数字图像处理--2.19图像水平镜像  [函数名称] 图像水平镜像函数MirrorXProcess(WriteableBitmap src) [函数代码]      ...

  8. Win8Metro(C#)数字图像处理--2.20图像垂直镜像

    原文:Win8Metro(C#)数字图像处理--2.20图像垂直镜像  [函数名称] 图像垂直镜像函数MirrorYProcess(WriteableBitmap src) [函数代码]      ...

  9. 【数字图像处理】五.MFC图像点运算之灰度线性变化、灰度非线性变化、阈值化和均衡化处理具体解释

    本文主要讲述基于VC++6.0 MFC图像处理的应用知识,主要结合自己大三所学课程<数字图像处理>及课件进行解说.主要通过MFC单文档视图实现显示BMP图片点运算处理.包含图像灰度线性变换 ...

  10. Win8 Metro(C#)数字图像处理--3.2图像方差计算

    原文:Win8 Metro(C#)数字图像处理--3.2图像方差计算 /// <summary> /// /// </summary>Variance computing. / ...

随机推荐

  1. vue中的computed和watch区别

    在vue.js官方文档中看到computed和watch获取全名的一个例子: var var vm = new Vue({ el: '#demo', data: { firstName: 'Foo', ...

  2. URL统一资源定位符

    URI 是统一资源标识符 URL 是统一资源定位符 ===================================================== 参考链接: 前端学HTTP之URL:ht ...

  3. python简单小程序

    #足球队寻找10 到12岁的小女孩(包含10岁和12岁),编写程序询问用户性别和年龄,然后显示一条消息指出这个人是否可以加入球队,询问10次,输出满足条件的总人数#询问10次,输出满足要求的总人数 o ...

  4. 记一次手工清除挖矿病毒WannaMine V4.0的经历

    [作者:byeyear    邮箱:byeyear@hotmail.com    转载请注明] 前两天公司信息安全处通知我的计算机存在永恒之蓝漏洞并已被病毒感染,使用多方杀软及专杀工具均无法有效清除, ...

  5. Docker Desktop for Windows Experience

    Docker Desktop for Windows Experience: https://github.com/poazy/boazy-learn/blob/master/doc/Docker%2 ...

  6. 22.文本框验证和外部url的调用

    面板可以右键固定到浏览器并且横向纵向都剧中 如果要在图片上进行点击或者其他操作 可以覆盖一个图片热区或者矩形(透明的)充当一个按钮的操作 这个提示的图片是默认隐藏的 通过右上角那个隐藏的勾 文本框右边 ...

  7. 如何让接口文档自动生成,SpringBoot中Swagger的使用

    目录 一.在SpringBoot项目中配置Swagger2 1.pom.xml中对Swagger2的依赖 2.编写配置类启用Swagger 3.配置实体类的文档 4.配置接口的文档 5.访问文档 二. ...

  8. 12款好用的Visual Studio插件,最后一款良心推荐

    目录 01 CodeMaid 02 Markdown Editor 03 ReSharper 04 GitHub Extension for Visual Studio 05 ZenCoding 06 ...

  9. 25.xlrd、xlwt和openpyxl模块的比较和使用

    xlrd.xlwt和openpyxl模块的比较:1)xlrd:对xls.xlsx.xlsm文件进行读操作–读操作效率较高,推荐2)xlwt:对xls文件进行写操作–写操作效率较高,但是不能执行xlsx ...

  10. 《图解机器学习-杉山将著》读书笔记---CH2

    CH2 学习模型 重点提炼 学习模型作用: 使特定函数与数据集相近似 学习模型类型: 1.线性模型 (1)最简单的线性模型,缺点:只能表现线性的输入输出函数,不能很好地解决实际问题 (2)基于参数的线 ...