C#图像处理之图像平移的方法
作者:沧海一粟…… 时间:2021-12-16 08:38:37
本文实例讲述了C#图像处理之图像平移的方法。分享给大家供大家参考。具体如下:
//定义图像平移函数
private static Bitmap offsetp(Bitmap a,int s,int v)
{
System.Drawing.Imaging.BitmapData srcData = a.LockBits(new Rectangle (0,0,a.Width ,a.Height) ,System .Drawing .Imaging .ImageLockMode .ReadWrite ,a.PixelFormat );
IntPtr ptr = srcData.Scan0;
int bytes = srcData.Stride * a.Height;
byte[]grayVlaues=new byte[bytes];
System.Runtime.InteropServices.Marshal.Copy(ptr ,grayVlaues ,0,bytes);
byte[] tempArray=new byte[bytes];
for (int i = 0; i < bytes; i++)
{
tempArray[i] = 255;
}
for (int i = 0; i < a.Width * 3; i += 3)
{
if ((i + s*3) < a.Width*3 && (i + s*3) > 0)
{
for (int j = 0; j < a.Height; j++)
{
if ((j + v) < a.Height && (j + v) > 0)
{
tempArray[(i + s * 3) + (j + v) * srcData.Stride] = grayVlaues[i + j * srcData.Stride];
tempArray[i + s * 3 + 1 + (j + v) * srcData.Stride] = grayVlaues[i + 1 + j * srcData.Stride];
tempArray[i + s * 3 + 2 + (j + v) * srcData.Stride] = grayVlaues[i + 2 + j * srcData.Stride];
}
}
}
}
grayVlaues = (byte[])tempArray.Clone();
System.Runtime.InteropServices.Marshal.Copy(grayVlaues ,0,ptr, bytes);
a.UnlockBits(srcData );
return a;
}
希望本文所述对大家的C#程序设计有所帮助。
标签:C#,图像,平移
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
一文详解kafka序列化器和拦截器
2023-06-18 01:06:08
![](https://img.aspxhome.com/file/2023/1/74751_0s.jpg)
java生成随机数的方法
2023-12-12 12:49:51
![](https://img.aspxhome.com/file/2023/4/65354_0s.jpg)
spring schedule实现动态配置执行时间
2022-09-06 18:47:30
Mybatis Lombok使用方法与复杂查询介绍
2023-03-30 00:30:13
![](https://img.aspxhome.com/file/2023/4/68764_0s.png)
关于Java中的IO流总结(推荐)
2023-08-23 18:13:56
![](https://img.aspxhome.com/file/2023/1/58191_0s.jpg)
java8使用filter()取出自己所需数据
2023-04-07 02:30:37
![](https://img.aspxhome.com/file/2023/9/71619_0s.png)
Java中的静态绑定和动态绑定详细介绍
2023-01-18 19:54:06
详解解密Java中的类型转换问题
2023-11-24 20:46:28
Java入门绊脚石之Override和Overload的区别详解
2022-05-04 15:24:51
![](https://img.aspxhome.com/file/2023/5/63445_0s.png)
使用IDEA开发配置Java Web的初始化过程
2022-09-25 16:33:38
![](https://img.aspxhome.com/file/2023/4/64794_0s.jpg)
spring boot实战教程之shiro session过期时间详解
2023-01-05 01:37:47
Kotlin语言编程Regex正则表达式实例详解
2023-06-22 02:06:29
jQuery 动画效果代码分享
2023-11-24 00:10:12
java 如何计算同比增长工具类
2023-11-09 08:50:35
深入理解Java设计模式之备忘录模式
2023-09-20 06:16:43
![](https://img.aspxhome.com/file/2023/3/58433_0s.jpg)
详解Spring Bean的集合注入和自动装配
2023-02-18 15:02:58
![](https://img.aspxhome.com/file/2023/9/60829_0s.jpg)
JAVA如何按字节截取字符串
2023-11-25 13:31:41
布隆过滤器面试如何快速判断元素是否在集合里
2022-10-17 15:55:19
![](https://img.aspxhome.com/file/2023/9/66939_0s.png)
spring如何实现两个xml配置文件间的互调
2021-06-07 20:50:15
![](https://img.aspxhome.com/file/2023/2/61522_0s.png)
JavaMail入门教程之解析邮件(5)
2023-11-29 08:25:13
![](https://img.aspxhome.com/file/2023/0/60030_0s.jpg)