打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
分享一段C#使用指针的代码!!
这效果你懂的。

这段代码使用了不安全代码,用了指针,要运行需要更改VS配置,Google下。看代码和效果:
 
C# code
/// <summary> /// 马赛克效果 ///原理:确定图像的随机位置点和确定马赛克块的大小,然后马赛克块图像覆盖随机点即可. /// </summary> /// <param name="m_Iimage"></param> /// <param name="val">分割成val*val像素的小区块</param> public Image MaSaiKe(Image m_PreImage , int val) { Bitmap MyBitmap = new Bitmap(m_PreImage); if (MyBitmap.Equals(null)) { return null; } int iWidth = MyBitmap.Width; int iHeight = MyBitmap.Height; int stdR , stdG , stdB; stdR = 0; stdG = 0; stdB = 0; BitmapData srcData = MyBitmap.LockBits(new Rectangle(0 , 0 , iWidth , iHeight) , ImageLockMode.ReadWrite , PixelFormat.Format24bppRgb); unsafe { byte* point = (byte*)srcData.Scan0.ToPointer(); for (int i = 0; i < iHeight; i++) { for (int j = 0; j < iWidth; j++) { if (i % val == 0) { if (j % val == 0) { stdR = point[2]; stdG = point[1]; stdB = point[0]; } else { point[0] = (byte)stdB; point[1] = (byte)stdG; point[2] = (byte)stdR; } } else { //复制上一行 byte* pTemp = point - srcData.Stride; point[0] = (byte)pTemp[0]; point[1] = (byte)pTemp[1]; point[2] = (byte)pTemp[2]; } point += 3; } point += srcData.Stride - iWidth * 3; } MyBitmap.UnlockBits(srcData); } return MyBitmap; }


效果:
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
C#中的图像处理(附带生成马赛克范例)
C#图片处理之:给你的图片打上LOGO
Led控件(2)
[转]RGB转换为灰度图的vc代码
C++单链表的动态创建,查找,遍历,删除,插入,添加,排序 - gengxiaoying的...
c#图像处理入门(
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服