/// <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); }