设为首页 加入收藏

TOP

C# 内存法图像处理(三)
2015-07-16 12:56:37 来源: 作者: 【 】 浏览:25
Tags:内存 图像处理
Scan0.ToPointer());
? ? ? ? ? ? ? ? ? ? for (int y = 0; y < oldData.Height - 1; y++)
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? for (int x = 0; x < oldData.Width; x++)
? ? ? ? ? ? ? ? ? ? ? ? {? ? ? ? ? ? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ? ? ? ? ? ? ? int b = (int)pin_1[0] - (int)pin_2[0] + 128;
? ? ? ? ? ? ? ? ? ? ? ? ? ? int g = (int)pin_1[1] - (int)pin_2[1] + 128;
? ? ? ? ? ? ? ? ? ? ? ? ? ? int r = (int)pin_1[2] - (int)pin_2[2] + 128;


? ? ? ? ? ? ? ? ? ? ? ? ? ? if (r < 0) r = 0;
? ? ? ? ? ? ? ? ? ? ? ? ? ? if (r > 255) r = 255;
? ? ? ? ? ? ? ? ? ? ? ? ? ? if (g < 0) g = 0;
? ? ? ? ? ? ? ? ? ? ? ? ? ? if (g > 255) g = 255;
? ? ? ? ? ? ? ? ? ? ? ? ? ? if (b < 0) b = 0;
? ? ? ? ? ? ? ? ? ? ? ? ? ? if (b > 255) b = 255;
? ? ? ? ? ? ? ? ? ? ? ? ? ? pout[0] = (byte)(b);
? ? ? ? ? ? ? ? ? ? ? ? ? ? pout[1] = (byte)(g);
? ? ? ? ? ? ? ? ? ? ? ? ? ? pout[2] = (byte)(r);
? ? ? ? ? ? ? ? ? ? ? ? ? ? pin_1 = pin_1 + 3;
? ? ? ? ? ? ? ? ? ? ? ? ? ? pin_2 = pin_2 + 3;
? ? ? ? ? ? ? ? ? ? ? ? ? ? pout = pout + 3;? ? ? ? ? ? ? ? ? ? ? ? ?
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? pin_1 += oldData.Stride - oldData.Width * 3;
? ? ? ? ? ? ? ? ? ? ? ? pin_2 += oldData.Stride - oldData.Width * 3;
? ? ? ? ? ? ? ? ? ? ? ? pout += newData.Stride - newData.Width * 3;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? bitmap.UnlockBits(newData);
? ? ? ? ? ? ? ? ? ? MyBitmap.UnlockBits(oldData);
? ? ? ? ? ? ? ? ? ? this.pbshowbox.Image = bitmap;
? ? ? ? ? ? ? ? }


? ? ? ? ? ? }
? ? ? ? ? ? else
? ? ? ? ? ? {
? ? ? ? ? ? ? ? MessageBox.Show("请先打开一张图片!");
? ? ? ? ? ? }
? ? ? ? }


五、底片


颜色值取反。



///


? ? ? ? /// 底片实现方法
? ? ? ? ///

? ? ? ? void Image_Negative()
? ? ? ? {
? ? ? ? ? ? if (pbshowbox.Image != null)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? int Height = this.pbshowbox.Image.Height;
? ? ? ? ? ? ? ? int Width = this.pbshowbox.Image.Width;
? ? ? ? ? ? ? ? Bitmap bitmap = new Bitmap(Width, Height, PixelFormat.Format24bppRgb);
? ? ? ? ? ? ? ? Bitmap MyBitmap = (Bitmap)this.pbshowbox.Image;
? ? ? ? ? ? ? ? BitmapData oldData = MyBitmap.LockBits(new Rectangle(0, 0, Width, Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
? ? ? ? ? ? ? ? BitmapData newData = bitmap.LockBits(new Rectangle(0, 0, Width, Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
? ? ? ? ? ? ? ? unsafe
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? byte* pin = (byte*)(oldData.Scan0.ToPointer());
? ? ? ? ? ? ? ? ? ? byte* pout = (byte*)(newData.Scan0.ToPointer());
? ? ? ? ? ? ? ? ? ? for (int y = 0; y < oldData.Height; y++)
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? for (int x = 0; x < oldData.Width; x++)
? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? pout[0] = (byte)(255 - pin[0]);
? ? ? ? ? ? ? ? ? ? ? ? ? ? pout[1] = (byte)(255 - pin[1]);
? ? ? ? ? ? ? ? ? ? ? ? ? ? pout[2] = (byte)(255 - pin[2]);
? ? ? ? ? ? ? ? ? ? ? ? ? ? pin = pin + 3;
? ? ? ? ? ? ? ? ? ? ? ? ? ? pout = pout + 3;
? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? pin += oldData.Stride - oldData.Width * 3;
? ? ? ? ? ? ? ? ? ? ? ? pout += newData.Stride - newData.Width * 3;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? bitmap.UnlockBits(newData);
? ? ? ? ? ? ? ? ? ? MyBitmap.UnlockBits(oldData);
? ? ? ? ? ? ? ? ? ? this.pbshowbox.Image = bitmap;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? else
? ? ? ? ? ? {
? ? ? ? ? ? ? ? MessageBox.Show("请先打开一张图片!");
? ? ? ? ? ? }
? ? ? ? }


六、积木


低像素置0,高像素置255。



///


? ? ? ? /// 积木实现方法
? ? ? ? ///

? ? ? ? private void Image_Block()
? ? ? ? {
? ? ? ? ? ? if (this.pbshowbox.Image != null)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? int Height = this.pbshowbox.Image.Height;
? ? ? ? ? ? ? ? int Width = this.pbshowbox.Image.Width;
? ? ? ? ? ? ? ? Bitmap bitmap = new Bitmap(Width, Height);
? ? ? ? ? ? ? ? Bitmap Mybitmap = (Bitmap)this.pbshowbox.Image;
? ? ? ? ? ? ? ? BitmapData oldData = Mybitmap.LockBits(new Rectangle(0, 0, Width, Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
? ? ? ? ? ? ? ? BitmapData newData = bitmap.LockBits(new Rectangle(0, 0, Width, Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
? ? ? ? ? ? ? ? unsafe
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? byte* pin = (byte*)(oldData.Scan0.ToPointer());
? ? ? ? ? ? ? ? ? ? byte* pout = (byte*)(newData.Scan0.ToPointer());
? ? ? ? ? ? ? ? ? ? for (int y = 0; y < oldData.Height; y++)
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? for (int x = 0; x < oldData.Width; x++)
? ? ? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? ? ? int avg = (pin[0] + p
首页 上一页 1 2 3 4 下一页 尾页 3/4/4
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇C++ sizeof总结 下一篇C++ 不使用virtual实现多态

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: