C#圖像處理之圖像平移的方法
更新時(shí)間:2015年04月24日 09:46:54 作者:滄海一粟……
這篇文章主要介紹了C#圖像處理之圖像平移的方法,涉及C#操作圖形實(shí)現(xiàn)平移的相關(guān)技巧,需要的朋友可以參考下
本文實(shí)例講述了C#圖像處理之圖像平移的方法。分享給大家供大家參考。具體如下:
//定義圖像平移函數(shù)
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#程序設(shè)計(jì)有所幫助。
您可能感興趣的文章:
- C#控制圖像旋轉(zhuǎn)和翻轉(zhuǎn)的方法
- C#中圖片旋轉(zhuǎn)和翻轉(zhuǎn)(RotateFlipType)用法分析
- C# 實(shí)現(xiàn)的圖片蓋章功能,支持拖拽、旋轉(zhuǎn)、放縮、保存
- C#利用GDI+繪制旋轉(zhuǎn)文字等效果實(shí)例
- C#實(shí)現(xiàn)計(jì)算一個(gè)點(diǎn)圍繞另一個(gè)點(diǎn)旋轉(zhuǎn)指定弧度后坐標(biāo)值的方法
- C#實(shí)現(xiàn)字體旋轉(zhuǎn)的方法
- 利用C#代碼實(shí)現(xiàn)圖片旋轉(zhuǎn)360度
- C# 使用 GDI+ 實(shí)現(xiàn)添加中心旋轉(zhuǎn)(任意角度)的文字
- c#實(shí)現(xiàn)圖片的平移和旋轉(zhuǎn)示例代碼
相關(guān)文章
C#實(shí)現(xiàn)從網(wǎng)絡(luò)同步標(biāo)準(zhǔn)北京時(shí)間的方法
這篇文章主要介紹了C#實(shí)現(xiàn)從網(wǎng)絡(luò)同步標(biāo)準(zhǔn)北京時(shí)間的方法,涉及C#操作時(shí)間的技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-03-03
詳解C#中delegate/event/EventHandler/Action/Func的使用和區(qū)別
這篇文章主要為大家詳細(xì)介紹了C#中delegate、event、EventHandler、Action和Func的使用與區(qū)別,文中的示例代碼講解詳細(xì),感興趣的可以了解一下2023-04-04
C#自定義序列化ISerializable的實(shí)現(xiàn)方法
這篇文章主要介紹了C#自定義序列化ISerializable的實(shí)現(xiàn)方法,涉及C#序列化的操作技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-04-04
c# 共享狀態(tài)的文件讀寫實(shí)現(xiàn)代碼
開發(fā)中有時(shí)會遇到要對文件進(jìn)行共享狀態(tài)的讀寫操作,代碼如下,需要的朋友可以參考下2012-06-06
C# TreeView讀取數(shù)據(jù)庫簡單實(shí)例
這篇文章主要介紹了2013-12-12

