Exemplo n.º 1
0
        private void TryCreateBackgroundBitmap()
        {
            if (RenderTarget != null && (imageHash != lastImageHash) && ((isDirty && BackgroundImage != null) || (background == null && BackgroundImage != null)))
            {
                using (var ms = new System.IO.MemoryStream()) {
                    ConvertImageToStreamAndAdjustBrightness(BackgroundImage, Data.BackgroundAlpha, ms);
                    ms.Position = 0;

                    using (var factory = WIC.ImagingFactory.Create()) {
                        using (WIC.BitmapDecoder decoder = factory.CreateDecoderFromStream(ms, WIC.DecodeMetadataCacheOption.OnDemand)) {
                            using (WIC.BitmapFrameDecode source = decoder.GetFrame(0)) {
                                using (WIC.FormatConverter converter = factory.CreateFormatConverter()) {
                                    converter.Initialize(source.ToBitmapSource(), WIC.PixelFormats.Pbgra32Bpp, WIC.BitmapDitherType.None, WIC.BitmapPaletteType.MedianCut);
                                    background    = RenderTarget.CreateBitmapFromWicBitmap(converter.ToBitmapSource());
                                    isDirty       = false;
                                    lastImageHash = imageHash;
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void TryCreateBackgroundBitmap()
        {
            if (RenderTarget != null && (imageHash != lastImageHash) && ((isDirty && BackgroundImage != null) || (background == null && BackgroundImage != null))) {

                using (var ms = new System.IO.MemoryStream()) {

                    ConvertImageToStreamAndAdjustBrightness(BackgroundImage, Data.BackgroundAlpha, ms);
                    ms.Position = 0;

                    using (var factory = WIC.ImagingFactory.Create()) {
                        using (WIC.BitmapDecoder decoder = factory.CreateDecoderFromStream(ms, WIC.DecodeMetadataCacheOption.OnDemand)) {
                            using (WIC.BitmapFrameDecode source = decoder.GetFrame(0)) {
                                using (WIC.FormatConverter converter = factory.CreateFormatConverter()) {
                                    converter.Initialize(source.ToBitmapSource(), WIC.PixelFormats.Pbgra32Bpp, WIC.BitmapDitherType.None, WIC.BitmapPaletteType.MedianCut);
                                    background = RenderTarget.CreateBitmapFromWicBitmap(converter.ToBitmapSource());
                                    isDirty = false;
                                    lastImageHash = imageHash;
                                }
                            }
                        }
                    }
                }
            }
        }