public IWICBitmapEncoder CreateEncoder(ContainerFormat format, Guid?guidVendor = null)
    {
        IWICBitmapEncoder encoder = CreateEncoder_(WIC.GetGuid(format), guidVendor);

        encoder._factory = this;
        return(encoder);
    }
Пример #2
0
        public static IWICBitmap CaptureXboxScreenshot()
        {
            var   cb             = 24883200;
            var   num            = Marshal.AllocCoTaskMem(cb: cb);
            ulong size           = (uint)cb;
            long  width          = 0;
            long  height         = 0;
            long  pitch          = 0;
            long  bitsPerChannel = 0;

            try {
                var windowsError = NativeMethods.CaptureScreenshot(buffer: num, size: size, width: out width, height: out height, pitch: out pitch, bitsPerChannel: out bitsPerChannel);
                if (windowsError != 0)
                {
                    throw new ScreenCaptureException(message: string.Format(format: "CaptureXboxScreenshot failed with result: {0}", arg0: windowsError), windowsError: windowsError);
                }
            } catch (Exception ex) {
                throw new ScreenCaptureException(message: string.Format(format: "CaptureXboxScreenshot threw '{0}' with message \"{1}'\"", arg0: ((object)ex).GetType(), arg1: ex.Message), innerException: ex);
            }

            if (height == 0L || width == 0L || pitch == 0L || bitsPerChannel == 0L)
            {
                throw new ScreenCaptureException(message: string.Format(format: "CaptureXboxScreenshot returned success but a returned value is 0. H: {0} W: {1} P: {2} BPC: {3}", (object)height, (object)width, (object)pitch, (object)bitsPerChannel));
            }
            Log.Out(msg: "CaptureXboxScreenshot call succeeded. H: {0} W: {1} P: {2} BPC: {3}", (object)height, (object)width, (object)pitch, (object)bitsPerChannel);
            var length   = (int)(height * width * 3L);
            var numArray = length <= cb ? new byte[length] : throw new ScreenCaptureException(message: string.Format(format: "CaptureXboxScreenshot returned a larger size screenshot than the allocated buffer. H: {0} W: {1} P: {2} BPC: {3}", (object)height, (object)width, (object)pitch, (object)bitsPerChannel));

            Marshal.Copy(source: num, destination: numArray, startIndex: 0, length: length);
            Marshal.FreeCoTaskMem(ptr: num);
            return(WIC.CreateImagingFactory().CreateBitmapFromMemory(uiWidth: (uint)width, uiHeight: (uint)height, pixelFormat: GUID_WICPixelFormat24bppRGB, cbStride: (uint)pitch, cbBufferSize: (uint)numArray.Length, pbBuffer: numArray) ?? throw new ScreenCaptureException(message: "CreateBitmapFromMemory returned null."));
        }
Пример #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="WicRenderTarget"/> class from a <see cref="SharpDX.WIC.Bitmap"/>.
 /// </summary>
 /// <param name="factory">The factory.</param>
 /// <param name="wicBitmap">The wic bitmap.</param>
 /// <param name="renderTargetProperties">The render target properties.</param>
 public WicRenderTarget(Factory factory, WIC.Bitmap wicBitmap, RenderTargetProperties renderTargetProperties)
     : base(IntPtr.Zero)
 {
     factory.CreateWicBitmapRenderTarget(wicBitmap, ref renderTargetProperties, this);
 }
Пример #4
0
 /// <summary>
 /// Creates a Bitmap from a wic bitmap.
 /// </summary>
 /// <param name="deviceContext">The render target.</param>
 /// <param name="wicBitmap">The wic bitmap.</param>
 /// <param name="bitmapProperties">The bitmap properties.</param>
 /// <returns></returns>
 /// <unmanaged>HRESULT ID2D1DeviceContext::CreateBitmapFromWicBitmap([In] IWICBitmapSource* wicBitmapSource,[In, Optional] const D2D1_BITMAP_PROPERTIES1* bitmapProperties,[Out] ID2D1Bitmap1** bitmap)</unmanaged>	
 public static Bitmap FromWicBitmap(DeviceContext deviceContext, WIC.BitmapSource wicBitmap, SharpDX.Direct2D1.BitmapProperties1 bitmapProperties)
 {
     Bitmap1 bitmap;
     deviceContext.CreateBitmapFromWicBitmap(wicBitmap, bitmapProperties, out bitmap);
     return bitmap;
 }
Пример #5
0
 /// <summary>
 /// Creates a Bitmap from a wic bitmap.
 /// </summary>
 /// <param name="deviceContext">The render target.</param>
 /// <param name="wicBitmapSource">A reference to a <see cref="SharpDX.WIC.BitmapSource"/> wic bitmap.</param>
 /// <returns></returns>
 /// <unmanaged>HRESULT ID2D1DeviceContext::CreateBitmapFromWicBitmap([In] IWICBitmapSource* wicBitmapSource,[In, Optional] const D2D1_BITMAP_PROPERTIES1* bitmapProperties,[Out] ID2D1Bitmap1** bitmap)</unmanaged>	
 public static Bitmap1 FromWicBitmap(DeviceContext deviceContext, WIC.BitmapSource wicBitmapSource)
 {
     Bitmap1 bitmap;
     deviceContext.CreateBitmapFromWicBitmap(wicBitmapSource, null, out bitmap);
     return bitmap;
 }
Пример #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ImageSourceFromWic"/>.
 /// </summary>
 public ImageSourceFromWic(DeviceContext2 context2, WIC.BitmapSource wicBitmapSource, ImageSourceLoadingOptions loadingOptions, AlphaMode alphaMode)
     : this(IntPtr.Zero)
 {
     context2.CreateImageSourceFromWic(wicBitmapSource, loadingOptions, alphaMode, this);
 }