Exemple #1
0
        private void CopyCommon(RenderTargetBitmap sourceBitmap)
        {
            _bitmapInit.BeginInit();
            _pixelWidth  = sourceBitmap._pixelWidth;
            _pixelHeight = sourceBitmap._pixelHeight;
            _dpiX        = sourceBitmap._dpiX;
            _dpiY        = sourceBitmap._dpiY;
            _format      = sourceBitmap._format;

            //
            // In order to make a deep clone we need to
            // create a new bitmap with the contents of the
            // existing bitmap and then create a render target
            // from the new bitmap.
            //
            using (FactoryMaker myFactory = new FactoryMaker())
            {
                // Create an IWICBitmap
                BitmapSourceSafeMILHandle newBitmapHandle = BitmapSource.CreateCachedBitmap(
                    null,
                    WicSourceHandle,
                    BitmapCreateOptions.PreservePixelFormat,
                    BitmapCacheOption.OnLoad,
                    null);

                lock (_syncObject)
                {
                    WicSourceHandle = newBitmapHandle;
                }

                // Now create a Render target from that Bitmap
                HRESULT.Check(UnsafeNativeMethods.MILFactory2.CreateBitmapRenderTargetForBitmap(
                                  myFactory.FactoryPtr,
                                  newBitmapHandle,
                                  out _renderTargetBitmap
                                  ));
            }

            _bitmapInit.EndInit();
        }