예제 #1
0
        /// <summary>
        /// Creates a WIC BitmapSource object from the given source.
        /// </summary>
        /// <param name="resourceLink">The source of the resource.</param>
        public static async Task <WicBitmapSource> FromResourceSourceAsync(ResourceLink resourceLink)
        {
            WicBitmapSourceInternal wicBitmapSource = null;

            using (Stream inStream = await resourceLink.OpenInputStreamAsync())
            {
                wicBitmapSource = await CommonTools.CallAsync(() => GraphicsHelper.LoadBitmapSource(inStream));
            }

            return(new WicBitmapSource(wicBitmapSource));
        }
예제 #2
0
        /// <summary>
        /// Creates a WIC bitmap from the given source.
        /// </summary>
        /// <param name="resourceLink">The source of the resource.</param>
        public static async Task <WicBitmap> FromResourceLinkAsync(ResourceLink resourceLink)
        {
            WIC.Bitmap wicBitmap = null;
            using (Stream inStream = await resourceLink.OpenInputStreamAsync())
                using (WicBitmapSourceInternal bitmapSourceWrapper = await CommonTools.CallAsync(() => GraphicsHelper.LoadBitmapSource(inStream)))
                {
                    wicBitmap = new WIC.Bitmap(
                        GraphicsCore.Current.FactoryWIC, bitmapSourceWrapper.Converter, WIC.BitmapCreateCacheOption.CacheOnLoad);
                }

            return(new WicBitmap(wicBitmap));
        }
        /// <summary>
        /// Gets the bitmap.
        /// </summary>
        /// <param name="engineDevice">The engine device.</param>
        internal override D2D.Bitmap GetBitmap(EngineDevice engineDevice)
        {
            if (base.IsDisposed)
            {
                throw new ObjectDisposedException(this.GetType().Name);
            }

            D2D.Bitmap result = m_loadedBitmaps[engineDevice.DeviceIndex];
            if (result == null)
            {
                using (Stream inputStream = m_resourceLink.OpenInputStream())
                    using (WicBitmapSourceInternal bitmapSourceWrapper = GraphicsHelper.LoadBitmapSource_D2D(inputStream))
                    {
                        WIC.BitmapSource bitmapSource = bitmapSourceWrapper.Converter;

                        // Store common properties about the bitmap
                        if (!m_firstLoadDone)
                        {
                            m_firstLoadDone = true;
                            m_pixelWidth    = bitmapSource.Size.Width;
                            m_pixelHeight   = bitmapSource.Size.Height;
                            if (m_totalFrameCount > 1)
                            {
                                m_framePixelWidth  = m_pixelWidth / m_framesX;
                                m_framePixelHeight = m_pixelHeight / m_framesY;
                            }
                            else
                            {
                                m_framePixelWidth  = m_pixelWidth;
                                m_framePixelHeight = m_pixelHeight;
                            }
                            bitmapSource.GetResolution(out m_dpiX, out m_dpyY);
                        }

                        // Load the bitmap into Direct2D
                        result = D2D.Bitmap.FromWicBitmap(
                            engineDevice.FakeRenderTarget2D, bitmapSource,
                            new D2D.BitmapProperties(new D2D.PixelFormat(
                                                         SharpDX.DXGI.Format.B8G8R8A8_UNorm,
                                                         D2D.AlphaMode.Premultiplied)));

                        // Register loaded bitmap
                        m_loadedBitmaps[engineDevice.DeviceIndex] = result;
                    }
            }


            return(result);
        }
예제 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="WicBitmapSource"/> class.
 /// </summary>
 /// <param name="bitmapSource">The bitmap source.</param>
 private WicBitmapSource(WicBitmapSourceInternal bitmapSource)
 {
     _wicBitmapSource = bitmapSource;
 }