Beispiel #1
0
        private void GetImageFromPath(RenderTarget pRenderer, string pPath)
        {
            using (System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(pPath))
            {
                System.Drawing.Imaging.BitmapData bmpData =
                    bitmap.LockBits(
                        new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height),
                        System.Drawing.Imaging.ImageLockMode.WriteOnly,
                        bitmap.PixelFormat
                        );

                Size = new Size(bitmap.Width, bitmap.Height);

                //// Declare an array to hold the bytes of the bitmap.
                //IntPtr ptr = bmpData.Scan0;

                //byte[] bytes = new byte[bmpData.Stride * bitmap.Height];

                // Unlock the bits.
                bitmap.UnlockBits(bmpData);
            }

            BitmapDecoder decoder = ImagingFactory.CreateDecoderFromFilename(pPath, DesiredAccess.Read, DecodeMetadataCacheOptions.OnDemand);

            BitmapFrameDecode  frameDeocder    = decoder.GetFrame(0);
            WICFormatConverter formatConverter = ImagingFactory.CreateFormatConverter();
            BitmapSource       src             = frameDeocder.ToBitmapSource();

            formatConverter.Initialize(frameDeocder.ToBitmapSource(), PixelFormats.Pf32bppPBGRA, BitmapDitherType.None, BitmapPaletteType.MedianCut);

            ImageResource = pRenderer.CreateBitmapFromWicBitmap(formatConverter.ToBitmapSource());
        }
Beispiel #2
0
        public static D2DBitmap GetBitmap(BitmapData pBitmapData, RenderTarget pRenderer)
        {
            try
            {
                BitmapDecoder decoder = ImagingFactory.CreateDecoderFromFilename(pBitmapData.FilePath, DesiredAccess.Read, DecodeMetadataCacheOptions.OnDemand);//.CreateDecoderFromStream(pBitmapData.Data, DecodeMetadataCacheOptions.OnDemand);

                BitmapFrameDecode  frameDeocder    = decoder.GetFrame(0);
                WICFormatConverter formatConverter = ImagingFactory.CreateFormatConverter();
                BitmapSource       src             = frameDeocder.ToBitmapSource();
                formatConverter.Initialize(frameDeocder.ToBitmapSource(), PixelFormats.Pf32bppPBGRA, BitmapDitherType.None, BitmapPaletteType.MedianCut);

                return(pRenderer.CreateBitmapFromWicBitmap(formatConverter.ToBitmapSource()));
            }
            catch (Exception)
            {
                return(null);
            }
        }