CSharpImageLibrary.ImageEngineImage.GetWPFBitmap C# (CSharp) Метод

GetWPFBitmap() приватный Метод

private GetWPFBitmap ( MipMap mip, int maxDimension, bool ShowAlpha ) : System.Windows.Media.Imaging.BitmapSource
mip MipMap
maxDimension int
ShowAlpha bool
Результат System.Windows.Media.Imaging.BitmapSource
        BitmapSource GetWPFBitmap(MipMap mip, int maxDimension, bool ShowAlpha)
        {
            BitmapSource bmp = null;

            if (maxDimension != 0)
            {
                // Choose a mip of the correct size, if available.
                var sizedMip = MipMaps.Where(m => (m.Height <= maxDimension && m.Width <= maxDimension) || (m.Width <= maxDimension && m.Height <= maxDimension));
                if (sizedMip.Any())
                {
                    var mip1 = sizedMip.First();
                    bmp = mip1.ToImage();
                }
                else
                {
                    double scale = (double)maxDimension / (Height > Width ? Height : Width);
                    mip = ImageEngine.Resize(mip, scale);
                    bmp = mip.ToImage();
                }         
            }
            else
                bmp = mip.ToImage();

            if (!ShowAlpha)
                bmp = new FormatConvertedBitmap(bmp, System.Windows.Media.PixelFormats.Bgr32, null, 0);

            bmp.Freeze();
            return bmp;
        }

Same methods

ImageEngineImage::GetWPFBitmap ( int maxDimension, bool ShowAlpha = false, int mipIndex ) : System.Windows.Media.Imaging.BitmapSource

Usage Example

        /// <summary>
        /// Creates a channel from an image. Can merge together with other channels to form a proper image again.
        /// MUST BE GRAYSCALE (PixelFormats.Gray8).
        /// </summary>
        /// <param name="mainPath">Path to channel.</param>
        public MergeChannelsImage(string mainPath)
        {
            FilePath = mainPath;

            var img = new ImageEngineImage(mainPath);
            {
                Width     = img.Width;
                Height    = img.Height;
                Thumbnail = img.GetWPFBitmap(128);
                //Pixels = img.MipMaps[0].Pixels;
            }
        }