Exemplo n.º 1
0
        public WriteableBitmap(IntPtr intPtr, int width, int height, PixelFormat pixelFormat)
        {
            Width         = width;
            Height        = height;
            PixelFormat   = pixelFormat;
            Stride        = CalculateStride(pixelFormat, width);
            Offset        = 0;
            BytesPerPixel = ((pixelFormat.BitsPerPixel + 7) / 8);
            Length        = width * height * BytesPerPixel;

            _memoryMapSection = intPtr;

            _mapView            = Win32Interop.MapViewOfFile(_memoryMapSection, 0xF001F, 0, 0, (UInt32)Length);
            _mustDisposeMapView = true;

            BitmapSource = (InteropBitmap)Imaging.CreateBitmapSourceFromMemorySection(_mapView, width, height, pixelFormat, Stride, Offset);
        }
Exemplo n.º 2
0
        public WriteableBitmap(int width, int height, PixelFormat pixelFormat)
        {
            Width         = width;
            Height        = height;
            PixelFormat   = pixelFormat;
            Stride        = CalculateStride(pixelFormat, width);
            Offset        = 0;
            BytesPerPixel = ((pixelFormat.BitsPerPixel + 7) / 8);
            Length        = width * height * BytesPerPixel;

            //IntPtr = Marshal.AllocHGlobal(Length);
            //this.MemoryMappedFile = MemoryMappedFile.CreateNew(null, Length, MemoryMappedFileAccess.ReadWrite);
            //IntPtr = this.MemoryMappedFile.CreateViewAccessor().SafeMemoryMappedViewHandle.DangerousGetHandle();

            _memoryMapSection            = Win32Interop.CreateFileMapping(new IntPtr(-1), IntPtr.Zero, 0x04, 0, (UInt32)Length, null);
            _mustDisposeMemoryMapSection = true;
            _mapView            = Win32Interop.MapViewOfFile(_memoryMapSection, 0xF001F, 0, 0, (UInt32)Length);
            _mustDisposeMapView = true;

            BitmapSource = (InteropBitmap)Imaging.CreateBitmapSourceFromMemorySection(_memoryMapSection, width, height, pixelFormat, Stride, Offset);
        }