예제 #1
0
파일: MyWin32.cs 프로젝트: BiDuc/PixelFarm
        /// <summary>
        /// Create a compatible memory HDC from the given HDC.<br/>
        /// The memory HDC can be rendered into without effecting the original HDC.<br/>
        /// The returned memory HDC and <paramref name="dib"/> must be released using <see cref="ReleaseMemoryHdc"/>.
        /// </summary>
        /// <param name="hdc">the HDC to create memory HDC from</param>
        /// <param name="width">the width of the memory HDC to create</param>
        /// <param name="height">the height of the memory HDC to create</param>
        /// <param name="dib">returns used bitmap memory section that must be released when done with memory HDC</param>
        /// <returns>memory HDC</returns>
        public static IntPtr CreateMemoryHdc(IntPtr hdc, int width, int height, out IntPtr dib, out IntPtr ppvBits)
        {
            // Create a memory DC so we can work off-screen
            IntPtr memoryHdc = MyWin32.CreateCompatibleDC(hdc);

            MyWin32.SetBkMode(memoryHdc, 1);
            // Create a device-independent bitmap and select it into our DC
            var info = new Win32.BitMapInfo();

            info.biSize        = Marshal.SizeOf(info);
            info.biWidth       = width;
            info.biHeight      = -height;
            info.biPlanes      = 1;
            info.biBitCount    = 32;
            info.biCompression = 0; // BI_RGB
            dib = MyWin32.CreateDIBSection(hdc, ref info, 0, out ppvBits, IntPtr.Zero, 0);
            MyWin32.SelectObject(memoryHdc, dib);
            return(memoryHdc);
        }
예제 #2
0
 /// <summary>
 /// Create a compatible memory HDC from the given HDC.<br/>
 /// The memory HDC can be rendered into without effecting the original HDC.<br/>
 /// The returned memory HDC and <paramref name="dib"/> must be released using <see cref="ReleaseMemoryHdc"/>.
 /// </summary>
 /// <param name="hdc">the HDC to create memory HDC from</param>
 /// <param name="width">the width of the memory HDC to create</param>
 /// <param name="height">the height of the memory HDC to create</param>
 /// <param name="dib">returns used bitmap memory section that must be released when done with memory HDC</param>
 /// <returns>memory HDC</returns>
 public static IntPtr CreateMemoryHdc(IntPtr hdc, int width, int height, out IntPtr dib, out IntPtr ppvBits)
 {
     // Create a memory DC so we can work off-screen
     IntPtr memoryHdc = MyWin32.CreateCompatibleDC(hdc);
     MyWin32.SetBkMode(memoryHdc, 1);
     // Create a device-independent bitmap and select it into our DC
     var info = new Win32.BitMapInfo();
     info.biSize = Marshal.SizeOf(info);
     info.biWidth = width;
     info.biHeight = -height;
     info.biPlanes = 1;
     info.biBitCount = 32;
     info.biCompression = 0; // BI_RGB 
     dib = MyWin32.CreateDIBSection(hdc, ref info, 0, out ppvBits, IntPtr.Zero, 0);
     MyWin32.SelectObject(memoryHdc, dib);
     return memoryHdc;
 }
예제 #3
0
파일: MyWin32.cs 프로젝트: BiDuc/PixelFarm
 public static extern IntPtr CreateDIBSection(IntPtr hdc, [In] ref Win32.BitMapInfo pbmi, uint iUsage, out IntPtr ppvBits, IntPtr hSection, uint dwOffset);