C#圖象處置之圖象平移的辦法。本站提示廣大學習愛好者:(C#圖象處置之圖象平移的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是C#圖象處置之圖象平移的辦法正文
本文實例講述了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#法式設計有所贊助。