Пример #1
0
 /// <summary>
 /// Creates a new <see cref="NativeBuffer"/> with the given dimensions.
 /// </summary>
 /// <param name="buffer">The storage location for the buffer object.</param>
 /// <param name="w">The width.</param>
 /// <param name="h">The height.</param>
 /// <param name="isDIB">True if the buffer should be DIB backed, false for Marshal.</param>
 /// <returns>Returns the data buffer.</returns>
 public static ARGB* CreateBuffer(out NativeBuffer buffer, int w, int h, bool isDIB)
 {
     ARGB* pixels;
     IntPtr handle;
     DeviceContext context = null;
     if(isDIB)
     {
         context = new DeviceContext();
         //create info
         BITMAPINFO info = new BITMAPINFO();
         //init with size
         info.init(w, h);
         //create DIB
         handle = CreateDIBSection(context.Handle, ref info, DIB_RGB_COLORS, out pixels, IntPtr.Zero, 0);
         WinAPIUtils.Assert(handle != IntPtr.Zero);
         //select the DIB into the DC
         context.Push(handle);
     }else
     {
         handle = Marshal.AllocHGlobal(w * h * 4);
         pixels = (ARGB*)handle;
     }
     //create buffer wrapper
     buffer = new NativeBuffer{isDIB = isDIB, Handle = handle, Context = context};
     //return the data
     return pixels;
 }
Пример #2
0
 /// <summary>
 /// Creates a new <see cref="DeviceContext"/> compatible with the given <see cref="DeviceContext"/>.
 /// </summary>
 /// <param name="deviceContext">The <see cref="DeviceContext"/></param>
 public DeviceContext(DeviceContext deviceContext)
 {
     Handle = CreateCompatibleDC(deviceContext.Handle);
     WinAPIUtils.Assert(Handle != IntPtr.Zero);
 }