日期:2014-05-17 浏览次数:20894 次
private Bitmap srcBitmap; public static int[] GetData(Bitmap a) { try { int w = a.Width; int h = a.Height; int[] sData = new int[w * h * 3]; Bitmap dstBitmap = new Bitmap(a.Width, a.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb); System.Drawing.Imaging.BitmapData srcData = a.LockBits(new Rectangle(0, 0, w, h), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb); System.Drawing.Imaging.BitmapData dstData = dstBitmap.LockBits(new Rectangle(0, 0, w, h), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb); unsafe { byte* pIn = (byte*)srcData.Scan0.ToPointer(); byte* pOut = (byte*)dstData.Scan0.ToPointer(); byte* p; int stride = srcData.Stride; int r, g, b; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { p = pIn; r = p[2]; g = p[1]; b = p[0]; sData[x * 3 + y * w * 3] = b; sData[x * 3 + 1 + y * w * 3] = g; sData[x * 3 + 2 + y * w * 3] = r; pIn += 3; pOut += 3; } pIn += srcData.Stride - w * 3; pOut += srcData.Stride - w * 3; } a.UnlockBits(srcData); dstBitmap.UnlockBits(dstData); return sData; } } catch (Exception e) { MessageBox.Show(e.Message.ToString()); return null; } } public static Bitmap Rebuildimage(int[] data, int w, int h) { try { Bitmap dstBitmap = new Bitmap(w, h, System.Drawing.Imaging.PixelFormat.Format24bppRgb); System.Drawing.Imaging.BitmapData dstData = dstBitmap.LockBits(new Rectangle(0, 0, w, h), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb); unsafe { byte* pOut = (byte*)dstData.Scan0.ToPointer(); int stride = dstData.Stride; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { pOut[0] = (byte)data[x * 3 + y * w * 3]; pOut[1] = (byte)data[x * 3 + 1 + y * w * 3]; pOut[2] = (byte)data[x * 3 + 2 + y * w * 3]; pOut += 3; } pOut += dstData.Stride - w * 3; } dstBitmap.UnlockBits(dstData); return dstBitmap; } } catch (Exception e) { MessageBox.Show(e.Message.ToString()); return null; } } public static int[] FunMirror(int[] srcData, double factor, int w, int h, int x, int y) { int cenX = x; int cenY = y; int newX = 0; int newY = 0; int offsetX =