Beispiel #1
0
        public static void FillGrayBitmap(this Bitmap bitmap, IMatrixLayer layer)
        {
            BitmapData bitmapData = bitmap.LockBits(new Rectangle(Point.Empty, bitmap.Size),
                                                    ImageLockMode.WriteOnly,
                                                    PixelFormat.Format8bppIndexed);
            IntPtr intPtr = bitmapData.Scan0;
            int    stride = bitmapData.Stride;
            int    bytes  = Math.Abs(stride) * bitmap.Height;

            byte[]             vs;// = new byte[bytes]; // Bitmap storage
            MatrixLayer <byte> byteLayer = layer.ToByteLayer(false);

            vs = byteLayer.GetStorage(false);
            if (bitmap.Width == stride)
            {
                System.Runtime.InteropServices.Marshal.Copy(vs, 0, intPtr, vs.Length);
            }
            else
            {
                int offsetArr = 0;
                int offsetPtr = 0;
                for (int i = 0; i < bitmap.Height; i++)
                {
                    System.Runtime.InteropServices.Marshal.Copy(vs, offsetArr, (intPtr + offsetPtr), layer.Width);
                    offsetArr += layer.Width;
                    offsetPtr += stride;
                }
            }
            bitmap.UnlockBits(bitmapData);
        }
Beispiel #2
0
        public static Mat <TElement> GetCVMat <TElement>(this MatrixLayer <TElement> layer)
            where TElement : unmanaged, IComparable <TElement>
        {
            Mat <TElement> mat = new Mat <TElement>(layer.Height, layer.Width);

            mat.SetArray(layer.GetStorage(false));
            return(mat);
        }
Beispiel #3
0
        public static void FillGrayBitmap(this Bitmap bitmap, IMatrixLayer layer)
        {
            BitmapData bitmapData = bitmap.LockBits(new Rectangle(Point.Empty, bitmap.Size),
                                                    ImageLockMode.WriteOnly,
                                                    PixelFormat.Format8bppIndexed);
            IntPtr intPtr = bitmapData.Scan0;
            int    stride = bitmapData.Stride;
            int    bytes  = Math.Abs(stride) * bitmap.Height;

            byte[]             vs;// = new byte[bytes]; // Bitmap storage
            MatrixLayer <byte> byteLayer = layer.ToByteLayer(false);

            vs = byteLayer.GetStorage(false);
            System.Runtime.InteropServices.Marshal.Copy(vs, 0, intPtr, bytes);
            bitmap.UnlockBits(bitmapData);
        }