Beispiel #1
0
 public static IntPtr CreateDIBSection(IntPtr hdc, ref BitmapInfo bitmapInfo,
                                       DibBmiColorUsageFlag iUsage, out IntPtr ppvBits, IntPtr hSection, uint dwOffset)
 {
     using (var pbmi = BitmapInfo.NativeAlloc(ref bitmapInfo))
     {
         return(Gdi32Methods.CreateDIBSection(hdc, pbmi.GetDangerousHandle(), iUsage, out ppvBits, hSection,
                                              dwOffset));
     }
 }
Beispiel #2
0
 public static IntPtr CreateDIBitmap(IntPtr hdc, ref BitmapInfoHeader
                                     lpbmih, uint fdwInit, byte[] lpbInit, ref BitmapInfo bitmapInfo,
                                     DibBmiColorUsageFlag fuUsage)
 {
     using (var pbmi = BitmapInfo.NativeAlloc(ref bitmapInfo))
     {
         return(Gdi32Methods.CreateDIBitmap(hdc, ref lpbmih, fdwInit, lpbInit, pbmi.GetDangerousHandle(),
                                            fuUsage));
     }
 }
Beispiel #3
0
 public static int SetDIBitsToDevice(IntPtr hdc, int xDest, int yDest, uint
                                     dwWidth, uint dwHeight, int xSrc, int ySrc, uint uStartScan, uint cScanLines,
                                     byte[] lpvBits, ref BitmapInfo bitmapInfo, DibBmiColorUsageFlag fuColorUse)
 {
     using (var pbmi = BitmapInfo.NativeAlloc(ref bitmapInfo))
     {
         return(Gdi32Methods.SetDIBitsToDevice(hdc, xDest, yDest,
                                               dwWidth, dwHeight, xSrc, ySrc, uStartScan, cScanLines, lpvBits, pbmi.GetDangerousHandle(),
                                               fuColorUse));
     }
 }
Beispiel #4
0
        public unsafe NativeBitmapInfoHandle(ref BitmapInfo bitmapInfo) : base(new IntPtr(0))
        {
            var quads       = bitmapInfo.Colors;
            var quadsLength = quads.Length;

            if (quadsLength == 0)
            {
                quadsLength = 1;
            }
            var success = false;
            var ptr     = IntPtr.Zero;

            try
            {
                ptr =
                    Marshal.AllocHGlobal(Marshal.SizeOf <BitmapInfoHeader>() + Marshal.SizeOf <RgbQuad>() * quadsLength);
                var headerPtr = (BitmapInfoHeader *)ptr.ToPointer();
                *   headerPtr = bitmapInfo.Header;
                var quadPtr   = (RgbQuad *)(headerPtr + 1);
                var i         = 0;
                for (; i < quads.Length; i++)
                {
                    *(quadPtr + i) = quads[i];
                }
                if (i == 0)
                {
                    *quadPtr = new RgbQuad();
                }
                this.SetHandle(ptr);
                success = true;
            }
            finally
            {
                if (!success)
                {
                    this.SetHandleAsInvalid();
                    Marshal.FreeHGlobal(ptr);
                }
            }
        }
Beispiel #5
0
 public static NativeBitmapInfoHandle NativeAlloc(ref BitmapInfo bitmapInfo)
 {
     return(new NativeBitmapInfoHandle(ref bitmapInfo));
 }