public Bitmap ToBitmap() { if (Map == null) { throw new NullReferenceException(); } var pf = FrameDataUtilities.Format(this); Bitmap bmp = new Bitmap(W, H, pf); var data = bmp.LockBits(new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, pf); for (int y = 0; y < H; y++) { Marshal.Copy(Map, y * Math.Abs(Stride), IntPtr.Add(data.Scan0, y * data.Stride), data.Stride); } bmp.UnlockBits(data); if (pf is System.Drawing.Imaging.PixelFormat.Format8bppIndexed) { bmp.SetGrayPallete(); } return(bmp); }
public void CopyFrom(IntPtr src, int h, int stride) { var posStride = Math.Abs(stride); for (int y = 0; y < h; y++) { FrameDataUtilities.CopyMemory(IntPtr.Add(DataPtr, y * posStride), IntPtr.Add(src, y * stride), (uint)posStride); } }
public System.Drawing.Bitmap ToBitmap() { if (DataPtr == null || DataPtr == IntPtr.Zero) { throw new NullReferenceException(); } var pf = FrameDataUtilities.Format(this); Bitmap bmp = new Bitmap(W, H, Stride, pf, DataPtr); if (pf is System.Drawing.Imaging.PixelFormat.Format8bppIndexed) { bmp.SetGrayPallete(); } return(bmp); }