c语言字符图像镜像,c#数字图像处理(九)图像镜像

这段代码展示了如何在C#中实现图像的镜像处理。通过LockBits和Marshal.Copy方法,程序能够读写位图数据,根据用户选择进行水平或垂直镜像。对于不同像素格式,如8bppIndexed和24bppRgb,代码处理方式有所不同,确保了像素值正确交换。
摘要由CSDN通过智能技术生成

private void mirror_Click(objectsender, EventArgs e)

{if (curBitmap!=null)

{

mirror mirForm= newmirror();if (mirForm.ShowDialog()==DialogResult.OK)

{

Rectangle rect= new Rectangle(0, 0, curBitmap.Width, curBitmap.Height);

BitmapData bmpData=curBitmap.LockBits(rect, ImageLockMode.ReadWrite, curBitmap.PixelFormat);

IntPtr ptr=bmpData.Scan0;int bytes = 0;判断是灰度色图像还是彩色图像,给相应的大小

if (curBitmap.PixelFormat==PixelFormat.Format8bppIndexed)

{

bytes= curBitmap.Width *curBitmap.Height;

}else if (curBitmap.PixelFormat ==PixelFormat.Format24bppRgb)

{

bytes= curBitmap.Width * curBitmap.Height * 3;

}byte[] pixelValues = new byte[bytes];

Marshal.Copy(ptr, pixelValues,0, bytes);//水平中轴

int halfWidth = curBitmap.Width / 2;//垂直中轴<

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值