c#数字图像处理(九)图像镜像
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#数字图像处理(九)图像镜像的更多相关文章
- Win8 Metro(C#) 数字图像处理--1 图像打开,保存
原文:Win8 Metro(C#) 数字图像处理--1 图像打开,保存 作为本专栏的第一篇,必不可少的需要介绍一下图像的打开与保存,一便大家后面DEMO的制作. Win8Metro编程中,图像相关 ...
- Win8 Metro(C#)数字图像处理--4图像颜色空间描述
原文:Win8 Metro(C#)数字图像处理--4图像颜色空间描述 图像颜色空间是图像颜色集合的数学表示,本小节将针对几种常见颜色空间做个简单介绍. /// <summary> / ...
- 数字图像处理,图像锐化算法的C++实现
http://blog.csdn.net/ebowtang/article/details/38961399 之前一段我们提到的算法都是和平滑有关, 经过平滑算法之后, 图像锐度降低, 降低到一定程度 ...
- 数字图像处理:图像的灰度变换(Matlab实现)
(1)线性变换:通过建立灰度映射来调整源图像的灰度. k>1增强图像的对比度:k=1调节图像亮度,通过改变d值达到调节亮度目的:0 i = imread('theatre.jpg');i = i ...
- 数字图像处理界标准图像 Lena 后面的故事
熟悉图像处理或者压缩的工程师.研究人员和学生,经常在他们的实验或者项目任务里使用"Lenna"或者"Lena"的图像.Lenna 图像已经成为被广泛使用的测试图 ...
- 【数字图像处理】六.MFC空间几何变换之图像平移、镜像、旋转、缩放具体解释
本文主要讲述基于VC++6.0 MFC图像处理的应用知识,主要结合自己大三所学课程<数字图像处理>及课件进行解说,主要通过MFC单文档视图实现显示BMP图片空间几何变换.包含图像平移.图形 ...
- Win8Metro(C#)数字图像处理--2.19图像水平镜像
原文:Win8Metro(C#)数字图像处理--2.19图像水平镜像 [函数名称] 图像水平镜像函数MirrorXProcess(WriteableBitmap src) [函数代码] ...
- Win8Metro(C#)数字图像处理--2.20图像垂直镜像
原文:Win8Metro(C#)数字图像处理--2.20图像垂直镜像 [函数名称] 图像垂直镜像函数MirrorYProcess(WriteableBitmap src) [函数代码] ...
- 【数字图像处理】五.MFC图像点运算之灰度线性变化、灰度非线性变化、阈值化和均衡化处理具体解释
本文主要讲述基于VC++6.0 MFC图像处理的应用知识,主要结合自己大三所学课程<数字图像处理>及课件进行解说.主要通过MFC单文档视图实现显示BMP图片点运算处理.包含图像灰度线性变换 ...
- Win8 Metro(C#)数字图像处理--3.2图像方差计算
原文:Win8 Metro(C#)数字图像处理--3.2图像方差计算 /// <summary> /// /// </summary>Variance computing. / ...
随机推荐
- 2018-8-10-resharper-跳转到源代码
title author date CreateTime categories resharper 跳转到源代码 lindexi 2018-08-10 19:16:52 +0800 2018-2-13 ...
- 树莓派4安装ftp服务端
vsftpd是开源的轻量级的常用ftp服务器. 1,安装vsftpd服务器 (约400KB) sudo apt-get install vsftpd 2,启动ftp服务 sudo serv ...
- CITRIX VPX安装
Step 1:下载.ova格式的VPX,如下图: Step 2:初始化VPX,如下图: 本例设置NSIP为192.168.188.150/24 Step 3:打开浏览器http://192.168.1 ...
- 解决IDEA使用terminal时 git log 乱码
1.配置环境变量: 变量名称-LESSCHARSET 变量值:utf-8 2.重启IDEA
- Android Library的依赖方式及发布(转)
还是那句老话,好记性不然烂笔头,在此整理 Android Studio 依赖相关 以及 如何发布项目到 JCenter Android Studio 添加依赖Module 依赖module 依赖是指在 ...
- python简单小程序
#足球队寻找10 到12岁的小女孩(包含10岁和12岁),编写程序询问用户性别和年龄,然后显示一条消息指出这个人是否可以加入球队,询问10次,输出满足条件的总人数#询问10次,输出满足要求的总人数 o ...
- 仿快播APP源码
目录 仿快播系统 一.项目总结三步走 二.项目需求分析 三.搭建框架 四.ORM框架分析 五.功能分析 六.项目开发--仿快播视频 服务端client start.py ---- 启动文件 conf ...
- RobotFramework+Appium 为了兼容iOS12,升级至Xcode10后,WebDriverAgent编译不通过:Undefind symbols for architecture x86_64
报错信息如下: Undefined symbols for architecture arm64: "_OBJC_CLASS_$_XCElementSnapshot", refer ...
- 怎么安装GUI
python安装easygui的过程中,下载的是0.97.安装的时候提示setuptools模块不存在.然后又去安装setuptools等等, 真麻烦.也没有成功.后来又下载了0.96的.才成功.下面 ...
- .NET Core 3 WPF MVVM框架 Prism系列之命令
本文将介绍如何在.NET Core3环境下使用MVVM框架Prism的命令的用法 一.创建DelegateCommand命令 我们在上一篇.NET Core 3 WPF MVVM框架 Prism系列之 ...