使用BitmapData实现图像的高速处理
2014-05-19 23:15
351 查看
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Drawing; using System.Drawing.Imaging; using System.Runtime.InteropServices; namespace 浮雕 { public class PhotoEmboss { public Bitmap Emboss(Bitmap _bmp, int pix, int angle) { Bitmap bmp = _bmp; Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height); BitmapData bmd = bmp.LockBits(rect, ImageLockMode.ReadWrite, bmp.PixelFormat); IntPtr ptr = bmd.Scan0; int w = bmd.Stride; int h = bmd.Height; int bytes = w * h; byte[] rgbValues = new byte[bytes]; Marshal.Copy(ptr, rgbValues, 0, bytes); byte colorTemp; byte colorNext; for (int i = 0; i < w - 4; i += 3) { for (int j = 0; j < h - 1; j++) { colorTemp = (byte)(rgbValues[j * w + i] * 0.299 + rgbValues[j * w + i + 1] * 0.587 + rgbValues[j * w + i + 2] * 0.114); colorNext = (byte)(rgbValues[(j + 1) * w + i + 3] * 0.299 + rgbValues[(j + 1) * w + i + 4] * 0.587 + rgbValues[(j + 1) * w + i + 5] * 0.114); int colorDif = colorTemp - colorNext + 128; colorDif = (colorDif < 0 || colorDif > 255) ? 0 : colorDif; rgbValues[j * w + i] = (byte)colorDif; rgbValues[j * w + i + 1] = (byte)colorDif; rgbValues[j * w + i + 2] = (byte)colorDif; } } Marshal.Copy(rgbValues, 0, ptr, bytes); bmp.UnlockBits(bmd); return bmp; } public Bitmap Emboss(Bitmap _bmp) { return Emboss(_bmp, 1, 135); } } }
相关文章推荐
- C#使用内存法Marshal 方法和BitMapData处理任意24位彩色图像
- 图形图像处理demo----drawable,bitmap,bitfactory的使用
- 使用QT实现一个图像处理软件1 —— 图片的加载和显示
- 使用Halcon实现图像处理
- (转)C#进行图像处理的几种方法(bitmap,bitmapData,IntPtr)
- 图像处理中使用多线程及图像分块实现加速运算
- Android Studio使用Opencv实现图像的实时处理
- Delphi下实现全屏快速找图找色 四、BitmapData.pas的使用
- Android图像处理(五)镜像、倒影、drawBitmapMesh实现旗帜飘扬效果
- 图像处理之基础---用Shader实现的YUV到RGB转换:使用3重纹理实现 .
- 使用bitmapData简单实现涂鸦中的橡皮功能(as3)
- Windows下Matlab使用G++ DLL实现图像处理
- 使用OpenCV 实现多摄像头图像处理笔记(1):DirectShow的配置过程可能出现的问题
- ROS学习笔记(2):在ROS中使用OpenCV进行简单的图像处理---代码实现篇
- OpenCV3计算机视觉Python语言实现(三):使用OpenCV3处理图像
- **ANDROID**# 第七章图形与图像处理(静态处理) > Bitmap是有像素点构成的点阵图。 ------ ## 使用简单的图片 ---- * 通过Drawable对象进行访问。
- Android Studio使用Opencv实现图像的实时处理
- 图像灰度直方图绘制——使用QT实现一个图像处理软件2
- (转)C#进行图像处理的几种方法(bitmap,bitmapData,IntPtr)