图像特效---Oilpaint油画滤镜
2016-05-10 21:36
363 查看
Oilpaint油画滤镜
核心代码如下:
///
/// Mosaic filter.
///
/// Source image.
/// The size of mosaic effect.
/// Resullt image.
public Bitmap OilpaintFilter(Bitmap src, int intensity)
{
Bitmap srcBitmap = new Bitmap(src);
int w = srcBitmap.Width;
int h = srcBitmap.Height;
System.Drawing.Imaging.BitmapData srcData = srcBitmap.LockBits(new Rectangle(0, 0, w, h), System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
IntPtr ptr = srcData.Scan0;
int bytes = h * srcData.Stride;
byte[] srcValues = new byte[bytes];
System.Runtime.InteropServices.Marshal.Copy(ptr, srcValues, 0, bytes);
byte[] tempValues = (byte[])srcValues.Clone();
int stride = srcData.Stride;
Random ran = new Random();
int k = 0;
int dx = 0;
int dy = 0;
for (int j = 0; j < h; j++)
{
for (int i = 0; i < w; i++)
{
k = ran.Next(intensity);
dx = (i + k) >= w ? w - 1 : (i + k);
dy = (j + k) >= h ? h - 1 : (j + k);
tempValues[i * 4 + j * w * 4] = (byte)srcValues[dx * 4 + dy * w * 4];
tempValues[i * 4 + 1 + j * w * 4] = (byte)srcValues[dx * 4 + 1 + dy * w * 4];
tempValues[i * 4 + 2 + j * w * 4] = (byte)srcValues[dx * 4 + 2 + dy * w * 4];
}
}
srcValues = (byte[])tempValues.Clone();
System.Runtime.InteropServices.Marshal.Copy(srcValues, 0, ptr, bytes);
srcBitmap.UnlockBits(srcData);
return srcBitmap;
}
程序demo: http://www.zealfilter.com/forum.php?mod=viewthread&tid=52&extra=page%3D2
核心代码如下:
///
/// Mosaic filter.
///
/// Source image.
/// The size of mosaic effect.
/// Resullt image.
public Bitmap OilpaintFilter(Bitmap src, int intensity)
{
Bitmap srcBitmap = new Bitmap(src);
int w = srcBitmap.Width;
int h = srcBitmap.Height;
System.Drawing.Imaging.BitmapData srcData = srcBitmap.LockBits(new Rectangle(0, 0, w, h), System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
IntPtr ptr = srcData.Scan0;
int bytes = h * srcData.Stride;
byte[] srcValues = new byte[bytes];
System.Runtime.InteropServices.Marshal.Copy(ptr, srcValues, 0, bytes);
byte[] tempValues = (byte[])srcValues.Clone();
int stride = srcData.Stride;
Random ran = new Random();
int k = 0;
int dx = 0;
int dy = 0;
for (int j = 0; j < h; j++)
{
for (int i = 0; i < w; i++)
{
k = ran.Next(intensity);
dx = (i + k) >= w ? w - 1 : (i + k);
dy = (j + k) >= h ? h - 1 : (j + k);
tempValues[i * 4 + j * w * 4] = (byte)srcValues[dx * 4 + dy * w * 4];
tempValues[i * 4 + 1 + j * w * 4] = (byte)srcValues[dx * 4 + 1 + dy * w * 4];
tempValues[i * 4 + 2 + j * w * 4] = (byte)srcValues[dx * 4 + 2 + dy * w * 4];
}
}
srcValues = (byte[])tempValues.Clone();
System.Runtime.InteropServices.Marshal.Copy(srcValues, 0, ptr, bytes);
srcBitmap.UnlockBits(srcData);
return srcBitmap;
}
程序demo: http://www.zealfilter.com/forum.php?mod=viewthread&tid=52&extra=page%3D2
相关文章推荐
- 再以Circle类为直接基类,派生出一个Cylinder(圆柱体)类,再增加数据成员h(高),,以及求圆柱表面积的成员函数area和求圆柱体积的成员函数volume,实现需要的成员函数,并设计main
- TensorFlow人工智能入门教程之十三 RCNN 区域卷积网络(视频侦测分析人脸侦测区域检测 )
- http://www.cnblogs.com/kristain/articles/2033566.html
- int main(int argc,char* argv[]),int main(int argc,char** argv)
- HDU 4393 Throw nails
- maridb Error 'Operation DROP USER failed for
- AIDL(跨进程通信传输语言)的用法
- LeetCode-11. Container With Most Water
- HDOJ 1021 Fibonacci Again
- 关于AIDL客户端与服务端交互的包名问题-package
- Kafka设计解析(三)- Kafka High Availability (下)
- Kafka设计解析(二)- Kafka High Availability (上)
- Rails中如何避免N+1问题
- Ex2010-03 figure out the number of mailboxes per database
- leetcode 336. Palindrome Pairs
- 传统图像、现代图像、人工智能时代图像算法工程师的研究内容
- svn cleanup failed–previous operation has not finished; run cleanup if it was interrupted
- 【CDMI-PROJECT】DAILY SUMMURY
- rsync故障排除解答
- 报错Resource temporarily unavailable