Inheritance: System.Windows.Media.Imaging.BitmapDecoder
Exemple #1
1
        /// <summary>
        /// Creates a WPF bitmap source from an GDI image.
        /// </summary>
        public static BitmapSource CreateBitmapSource(Image image)
        {
            MemoryStream stream = new MemoryStream();
            //int width = image.Width;
            //int height = image.Height;
            //double dpiX = image.HorizontalResolution;
            //double dpiY = image.VerticalResolution;
            //System.Windows.Media.PixelFormat pixelformat = PixelFormats.Default;
            BitmapSource bitmapSource = null;

            try
            {
                string guid = image.RawFormat.Guid.ToString("B").ToUpper();
                switch (guid)
                {
                    case "{B96B3CAA-0728-11D3-9D7B-0000F81EF32E}":  // memoryBMP
                    case "{B96B3CAB-0728-11D3-9D7B-0000F81EF32E}":  // bmp
                        image.Save(stream, ImageFormat.Bmp);
                        stream.Position = 0;
                        BmpBitmapDecoder bmpDecoder = new BmpBitmapDecoder(stream, BitmapCreateOptions.None, BitmapCacheOption.Default);
                        bitmapSource = bmpDecoder.Frames[0];
                        break;

                    case "{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}":  // png
                        image.Save(stream, ImageFormat.Png);
                        stream.Position = 0;
                        PngBitmapDecoder pngDecoder = new PngBitmapDecoder(stream, BitmapCreateOptions.None, BitmapCacheOption.Default);
                        bitmapSource = pngDecoder.Frames[0];
                        break;

                    case "{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}":  // jpeg
                        image.Save(stream, ImageFormat.Jpeg);
                        JpegBitmapDecoder jpegDecoder = new JpegBitmapDecoder(stream, BitmapCreateOptions.None, BitmapCacheOption.Default);
                        stream.Position = 0;
                        bitmapSource = jpegDecoder.Frames[0];
                        break;

                    case "{B96B3CB0-0728-11D3-9D7B-0000F81EF32E}":  // gif
                        image.Save(stream, ImageFormat.Gif);
                        GifBitmapDecoder gifDecoder = new GifBitmapDecoder(stream, BitmapCreateOptions.None, BitmapCacheOption.Default);
                        stream.Position = 0;
                        bitmapSource = gifDecoder.Frames[0];
                        break;

                    case "{B96B3CB1-0728-11D3-9D7B-0000F81EF32E}":  // tiff
                        image.Save(stream, ImageFormat.Tiff);
                        TiffBitmapDecoder tiffDecoder = new TiffBitmapDecoder(stream, BitmapCreateOptions.None, BitmapCacheOption.Default);
                        stream.Position = 0;
                        bitmapSource = tiffDecoder.Frames[0];
                        break;

                    case "{B96B3CB5-0728-11D3-9D7B-0000F81EF32E}":  // icon
                        image.Save(stream, ImageFormat.Icon);
                        IconBitmapDecoder iconDecoder = new IconBitmapDecoder(stream, BitmapCreateOptions.None, BitmapCacheOption.Default);
                        stream.Position = 0;
                        bitmapSource = iconDecoder.Frames[0];
                        break;

                    case "{B96B3CAC-0728-11D3-9D7B-0000F81EF32E}":  // emf
                    case "{B96B3CAD-0728-11D3-9D7B-0000F81EF32E}":  // wmf
                    case "{B96B3CB2-0728-11D3-9D7B-0000F81EF32E}":  // exif
                    case "{B96B3CB3-0728-11D3-9D7B-0000F81EF32E}":  // photoCD
                    case "{B96B3CB4-0728-11D3-9D7B-0000F81EF32E}":  // flashPIX

                    default:
                        throw new InvalidOperationException("Unsupported image format.");
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("ImageHelper.CreateBitmapSource failed:" + ex.Message);
            }
            finally
            {
                //if (stream != null)
                //  stream.Close();
            }
            return bitmapSource;
        }
        /// <summary>
        /// Method loads all icon sizes from icon and sets icon with max size to image
        /// </summary>
        private void _SetMaxSizeIconToImage()
        {
            Uri iconUri = new Uri(ICON_PATH);

            // load icon
            StreamResourceInfo iconInfo = Application.GetResourceStream(iconUri);
            Stream iconStream = iconInfo.Stream;
            IconBitmapDecoder iconBitmapDecoder = new IconBitmapDecoder(iconStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.None);

            // if icon file contains more than 1 size - find frame with max size
            if (iconBitmapDecoder.Frames.Count > 1)
            {
                double maxHeight = 0;
                double maxWidth = 0;
                BitmapFrame sourceFrame = default(BitmapFrame);

                foreach (BitmapFrame bitmapFrame in iconBitmapDecoder.Frames)
                {
                    if (bitmapFrame.Height > maxHeight && bitmapFrame.Width > maxWidth)
                    {
                        sourceFrame = bitmapFrame; // save found frame in sourceFrame
                        maxHeight = bitmapFrame.Height;
                        maxWidth = bitmapFrame.Width;
                    }
                }

                image.Source = sourceFrame; // set max size frame as image source
            }
        }
        public Window1()
        {
            #region Uninstall Catcher
            string[] args=Environment.GetCommandLineArgs();
            foreach (string arg in args)
                if (arg.Split('=')[0].ToLower() == "/u")
                {
                    string guid = arg.Split('=')[1];
                    string path = Environment.GetFolderPath(System.Environment.SpecialFolder.System);
                    string str = path + "\\msiexec.exe";
                    ProcessStartInfo pi = new ProcessStartInfo(str);
                    pi.Arguments = "/i " + guid;
                    pi.UseShellExecute = false;
                    Process.Start(pi);
                    this.Close();
                    return;
                }
            #endregion

            InitializeComponent();

            IconBitmapDecoder icon = new IconBitmapDecoder(iconUri, BitmapCreateOptions.None, BitmapCacheOption.Default);
            this.Icon = icon.Frames[0];

            this.Closing += new System.ComponentModel.CancelEventHandler(Window1_Closing);
            this.Loaded += new RoutedEventHandler(Window1_Loaded);
        }
Exemple #4
0
        public Window1()
        {
            InitializeComponent();

            _systemtray = new System.Windows.Forms.NotifyIcon();

            Assembly a = Assembly.GetExecutingAssembly();
            Stream logoStream = a.GetManifestResourceStream("YAWAMT.SystemTrayClient.yawamt.ico");

            _systemtray.Icon = new System.Drawing.Icon(logoStream);
            _systemtray.Visible = true;

            _systemtray.Click += new EventHandler(SystemTrayIcon_Click);
            _systemtray.MouseMove += new System.Windows.Forms.MouseEventHandler(SystemTrayIcon_MouseMove);
            _systemtray.BalloonTipShown += new EventHandler(SystemTrayIcon_BalloonTipShown);
            _systemtray.BalloonTipClosed += new EventHandler(SystemTrayIcon_BalloonTipClosed);

            _systemtray.BalloonTipIcon = System.Windows.Forms.ToolTipIcon.Info;
            _systemtray.BalloonTipTitle = "yawamt";
            _systemtray.BalloonTipText = "3 down, 5 up";

            AttachContextMenu();

            try
            {
                IconBitmapDecoder decoder = new IconBitmapDecoder(logoStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
                imglogo.Source = decoder.Frames[0];
            }
            catch { }

            this.Hide();

            //if (string.IsNullOrEmpty(YAWAMT.SystemTrayClient.Properties.Settings.Default.Url))
            //    ContextMenuSettings(this, EventArgs.Empty);
        }
        public MainWindow()
        {
            try
            {
                InitializeComponent();
            }
            catch (Exception ex)
            {
                Logging.LogException(ex);
                throw;
            }

            EventManager.RegisterClassHandler(typeof(TreeViewItem),
                                Mouse.MouseDownEvent, new MouseButtonEventHandler(OnTreeViewItemMouseDown), false);

            try
            {
                IconBitmapDecoder ibd = new IconBitmapDecoder(
                new Uri(@"pack://application:,,/DafuscatorIcon.ico", UriKind.RelativeOrAbsolute),
                BitmapCreateOptions.None,
                BitmapCacheOption.Default);
                Icon = ibd.Frames[0];
            }
            catch (Exception ex) { }

            SkinManager.SkinId = SkinId.OfficeBlack;

            SetWindowTitle();
            Initialize();
        }
Exemple #6
0
        /// <summary>
        /// Extracts a specific image from an ico
        /// file given it's size.
        /// If no exact size is matched, the largest 
        /// image will be returned.
        /// </summary>
        /// <param name="path">The path to the ico</param>
        /// <param name="width">The prefered width</param>
        /// <param name="height">The prefered height</param>
        /// <returns>An image from inside the ico file</returns>
        public static BitmapFrame GetIcoImage(string path, int width, int height)
        {
            if (!path.StartsWith("pack://") && !path.Contains('\\') && !path.Contains('/'))
                path = "pack://application:,,,/Platform/Windows 7/GUI/Images/Icons/" + path + ".ico";
            var iconUri = new Uri(path, UriKind.RelativeOrAbsolute);
            try
            {

                var iconDecoder = new IconBitmapDecoder(iconUri,
                    BitmapCreateOptions.None, BitmapCacheOption.Default);

                // no image found
                if (iconDecoder.Frames.Count == 0) return null;

                BitmapFrame largest = iconDecoder.Frames[0];
                foreach (BitmapFrame frame in iconDecoder.Frames)
                {
                    if (frame.PixelHeight == height &&
                        frame.PixelWidth == width)
                    {
                        return frame;
                    }

                    if (frame.PixelWidth * frame.PixelHeight >
                        largest.PixelWidth * frame.PixelHeight)
                        largest = frame;
                }

                return largest;
            }
            catch (Exception)
            {
                return null;
            }
        }
Exemple #7
0
        private void rbtOQA_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            //e.Handled = true;
            UserInformation _userInformation    = new UserInformation();
            string          hostname            = Dns.GetHostName();
            int             maxLengthOfUserName = 15;

            _userInformation.UserName      = hostname.IsNotNullOrEmpty() ? hostname.Substring(0, (hostname.Trim().Length > maxLengthOfUserName ? maxLengthOfUserName : hostname.Trim().Length)) : string.Empty;
            _userInformation.Dal           = loggedon.Dal;
            _userInformation.SFLPDDatabase = loggedon.DB;
            _userInformation.UserRole      = "OQA";
            _userInformation.Version       = loggedon.GetVersion();

            string applicationTitle = "SmartPD - ";

            Window win = new Window();

            win.Title = Title = applicationTitle + "Operator Quality Assurance Chart";

            ProcessDesigner.frmOperatorQualityAssurance    objRptOQA = new ProcessDesigner.frmOperatorQualityAssurance(_userInformation, win, -9999, OperationMode.AddNew, win.Title);
            System.Windows.Media.Imaging.IconBitmapDecoder ibd       = new System.Windows.Media.Imaging.IconBitmapDecoder(new Uri(@"pack://application:,,/Images/logo.ico", UriKind.RelativeOrAbsolute), System.Windows.Media.Imaging.BitmapCreateOptions.None, System.Windows.Media.Imaging.BitmapCacheOption.Default);
            win.Icon = ibd.Frames[0];

            win.Content               = objRptOQA;
            win.MinHeight             = objRptOQA.Height + 50;
            win.MinWidth              = objRptOQA.Width + 10;
            win.ShowInTaskbar         = true;
            win.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            win.WindowState           = WindowState.Maximized;
            win.ResizeMode            = System.Windows.ResizeMode.CanResize;
            objRptOQA.Height          = win.Height - 50;
            objRptOQA.Width           = win.Width - 10;
            this.Close();
            win.Show();
        }
Exemple #8
0
        private static ImageSource RetriveImage(string imagePath)
        {
            Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(imagePath);

            switch (imagePath.Substring(imagePath.Length - 3))
            {
            case "jpg":
                var jpgDecoder = new System.Windows.Media.Imaging.JpegBitmapDecoder(stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
                return(jpgDecoder.Frames[0]);

            case "bmp":
                var bmpDecoder = new System.Windows.Media.Imaging.BmpBitmapDecoder(stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
                return(bmpDecoder.Frames[0]);

            case "png":
                var pngDecoder = new System.Windows.Media.Imaging.PngBitmapDecoder(stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
                return(pngDecoder.Frames[0]);

            case "ico":
                var icoDecoder = new System.Windows.Media.Imaging.IconBitmapDecoder(stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
                return(icoDecoder.Frames[0]);

            default:
                return(null);
            }
        }
Exemple #9
0
        public AboutTabVM(AppVM app)
            : base(app, "About")
        {
            var decoder = new IconBitmapDecoder(new Uri("pack://application:,,,/ConfuserEx.ico"), BitmapCreateOptions.DelayCreation, BitmapCacheOption.OnDemand);

            Icon = decoder.Frames.First(frame => frame.Width == 64);
        }
 public override bool View(DecompilerTextView textView)
 {
   try
   {
     AvalonEditTextOutput output = new AvalonEditTextOutput();
     Data.Position = 0;
     IconBitmapDecoder decoder = new IconBitmapDecoder(Data, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.None);
     foreach (var frame in decoder.Frames)
     {
       output.Write(String.Format("{0}x{1}, {2} bit: ", frame.PixelHeight, frame.PixelWidth, frame.Thumbnail.Format.BitsPerPixel));
       AddIcon(output, frame);
       output.WriteLine();
     }
     output.AddButton(Images.Save, "Save", delegate
     {
       Save(null);
     });
     textView.ShowNode(output, this);
     return true;
   }
   catch (Exception)
   {
     return false;
   }
 }
Exemple #11
0
 public static ImageSource GetIcon(Uri uri)
 {
     var ibd = new IconBitmapDecoder(
         uri,
         BitmapCreateOptions.None,
         BitmapCacheOption.Default);
     return ibd.Frames[0];
 }
Exemple #12
0
 private ImageSource GetImageFromAssociatedIcon()
 {
     var ico = System.Drawing.Icon.ExtractAssociatedIcon(Target);
     MemoryStream strm = new MemoryStream();
     ico.Save(strm);
     IconBitmapDecoder ibd = new IconBitmapDecoder(strm, BitmapCreateOptions.None, BitmapCacheOption.Default);
     return ibd.Frames[0];
 }
 public MainWindow()
 {
     InitializeComponent();
     var thisAssembly=Assembly.GetExecutingAssembly();
     var stream=thisAssembly.GetManifestResourceStream("BenzGorokuSearch.benz.ico");
     var decoder=new IconBitmapDecoder(stream,BitmapCreateOptions.DelayCreation,BitmapCacheOption.Default);
     Icon=decoder.Frames[0];
     DataContext=new MainWindowViewModel();
 }
 public MainWindow()
 {
     InitializeComponent();
     var thisAssembly=Assembly.GetExecutingAssembly();
     var stream=thisAssembly.GetManifestResourceStream("GorokuEdit.benz.ico");
     var image=new IconBitmapDecoder(stream,BitmapCreateOptions.DelayCreation,BitmapCacheOption.Default);
     Icon=image.Frames[0];
     viewModel=new MainWindowViewModel();
     DataContext=viewModel;
 }
		public DebuggerDialog(bool isMain = true) {
			InitializeComponent();

			string icon = "cde.ico";
			Stream bitmapStream;
			try {
				bitmapStream = new MemoryStream(ApplicationManager.GetResource(icon));
			}
			catch {
				bitmapStream = null;
				MessageBox.Show("Couldn't find the icon file in the program's resources. The icon must be a .ico file and it must be placed within the application's resources (embedded resource).");
				if (TkWindow.ShutDownOnInvalidIcons)
					ApplicationManager.Shutdown();
			}
			if (bitmapStream == null) {
				MessageBox.Show("Couldn't find the icon file in the program's resources.");
				if (!TkWindow.ShutDownOnInvalidIcons)
					return;
				ApplicationManager.Shutdown();
			}
			else {
				try {
					Icon = new IconBitmapDecoder(bitmapStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.None).Frames[0];
				}
				catch (Exception) {
					try {
						Icon = ApplicationManager.GetResourceImage(icon);
						return;
					}
					catch {
					}
					MessageBox.Show("Invalid icon file.");
					if (!TkWindow.ShutDownOnInvalidIcons)
						return;
					Application.Current.Shutdown();
				}
			}

			Extensions.GenerateListViewTemplate(_listViewStackTrace, new ListViewDataTemplateHelper.GeneralColumnInfo[] {
				new ListViewDataTemplateHelper.GeneralColumnInfo { Header = "File name", DisplayExpression = "FileName", ToolTipBinding="FileName", TextAlignment = TextAlignment.Right, FixedWidth = 180 },
				new ListViewDataTemplateHelper.GeneralColumnInfo { Header = "Line", DisplayExpression = "Line", ToolTipBinding="Line", TextAlignment = TextAlignment.Left, FixedWidth = 60 },
				new ListViewDataTemplateHelper.GeneralColumnInfo { Header = "Method", DisplayExpression = "Method", ToolTipBinding="Method", TextAlignment = TextAlignment.Left, IsFill = true}
			}, null, new string[] { "Default", "Black" });

			Loaded += _loaded;
			Left = 0;
			Top = 0;

			if (!isMain)
				_enableClosing = true;

			new Thread(_backgroundWindowOwnership) { Name = "GrfEditor - Debugger primary thread" }.Start();
		}
Exemple #16
0
		private void SetWindowIcon()
		{
			try
			{
				IconBitmapDecoder ibd = new IconBitmapDecoder(
				new Uri("pack://application:,,,/" + GetType().Assembly.GetName().Name + ";component/Scutex2.ico", UriKind.RelativeOrAbsolute),
				BitmapCreateOptions.None,
				BitmapCacheOption.Default);
				Icon = ibd.Frames[0];
			}
			catch
			{ }

		}
        public static BitmapSource ToBitmapSource(this Icon icon)
        {
            if (icon == null)
                return null;

            using (var stream = new MemoryStream())
            {
                using (icon) icon.Save(stream);
                var ico = new IconBitmapDecoder(
                    stream,
                    BitmapCreateOptions.PreservePixelFormat,
                    BitmapCacheOption.Default);

                return ico.Frames.First();
            }
        }
Exemple #18
0
        public MainWindow()
        {
            InitializeComponent();

            try
            {
                IconBitmapDecoder ibd = new IconBitmapDecoder(
                    new Uri(@"pack://application:,,/Insight.ico", UriKind.RelativeOrAbsolute),
                    BitmapCreateOptions.None,
                    BitmapCacheOption.Default);
                Icon = ibd.Frames[0];
            }
            catch { }

            SkinManager.SkinId = SkinId.OfficeBlack;
        }
Exemple #19
0
        public MainWindow()
        {
            InitializeComponent();

            try
            { // Apparently this doesn't work in anything but Windows7
                IconBitmapDecoder ibd = new IconBitmapDecoder(
                new Uri(@"pack://*****:*****@"pack://application:,,/Scutex3.ico", UriKind.RelativeOrAbsolute),
                    BitmapCreateOptions.None,
                    BitmapCacheOption.Default);
                    Icon = ibd.Frames[0];
                }
                catch { }
            }

            this.Title = ApplicationConstants.IsCommunityEdition ? "Scutex Licensing Manager (Community Edition)" : "Scutex Licensing Manager (Professional Edition)";

            try
            {
                Bootstrapper.Configure();

                _eventAggregator = ObjectLocator.GetInstance<IEventAggregator>();
                _eventAggregator.AddListener<ProductsUpdatedEvent>(x => RefreshData());
                _eventAggregator.AddListener<LicenseSavedEvent>(x => SetRecentItemsAndRefresh());
                _eventAggregator.AddListener<ServicesUpdatedEvent>(x => RefreshData());
            }
            catch { }

            Initalize();

            SetRecentItems();

            VerifyFirstTimeRun();

            WelcomeScreenForm welcomeScreenForm = new WelcomeScreenForm();
            root.Content = welcomeScreenForm;
        }
Exemple #20
0
        /// <summary>
        /// 从资源中恢复图像(png、ico、jpeg、bmp)
        /// </summary>
        /// <param name="nomImage"></param>
        /// <returns></returns>
        public static ImageSource ImageSource(string nomImage)
        {
            Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(nomImage);

            if (Path.GetExtension(nomImage).ToLower().EndsWith(".png")) // Cas png
            {
                PngBitmapDecoder img = new System.Windows.Media.Imaging.PngBitmapDecoder(stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
                return(img.Frames[0]);
            }

            if (Path.GetExtension(nomImage).ToLower().EndsWith(".bmp")) // Cas bmp
            {
                BmpBitmapDecoder img = new System.Windows.Media.Imaging.BmpBitmapDecoder(stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
                return(img.Frames[0]);
            }

            if (Path.GetExtension(nomImage).ToLower().EndsWith(".jpg")) // Cas jpg
            {
                JpegBitmapDecoder img = new System.Windows.Media.Imaging.JpegBitmapDecoder(stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
                return(img.Frames[0]);
            }

            if (Path.GetExtension(nomImage).ToLower().EndsWith(".tiff")) // Cas tiff
            {
                TiffBitmapDecoder img = new System.Windows.Media.Imaging.TiffBitmapDecoder(stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
                return(img.Frames[0]);
            }

            if (Path.GetExtension(nomImage).ToLower().Contains(".ico")) // Cas  ico
            {
                IconBitmapDecoder img = new System.Windows.Media.Imaging.IconBitmapDecoder(stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
                return(img.Frames[0]);
            }

            return(null);
        }
 public ReadExifInfo(string fileName, FileInfo file)
 {
     try
     {
         using (foto = File.Open(fileName, FileMode.Open, FileAccess.Read))
         {
             JpegBitmapDecoder jpegdecoder;
             PngBitmapDecoder pngdecoder;
             BmpBitmapDecoder bmpdecoder;
             GifBitmapDecoder gifdecoder;
             IconBitmapDecoder icondecoder;
             TiffBitmapDecoder tiffdecoder;
             WmpBitmapDecoder wmpdecoder;
                 
             switch(file.Extension.ToLower())
             {
                 case ".jpg":
                     jpegdecoder = new JpegBitmapDecoder(foto, BitmapCreateOptions.IgnoreColorProfile, BitmapCacheOption.Default);
                     bm = (BitmapMetadata)jpegdecoder.Frames[0].Metadata.Clone();
                     break;
                 case ".jpeg":
                     jpegdecoder = new JpegBitmapDecoder(foto, BitmapCreateOptions.IgnoreColorProfile, BitmapCacheOption.Default);
                     bm = (BitmapMetadata)jpegdecoder.Frames[0].Metadata.Clone();
                     break;
                 case ".png":
                     pngdecoder = new PngBitmapDecoder(foto, BitmapCreateOptions.IgnoreColorProfile, BitmapCacheOption.Default);
                     bm = (BitmapMetadata)pngdecoder.Frames[0].Metadata.Clone();
                     break;
                 case ".bmp":
                     bmpdecoder = new BmpBitmapDecoder(foto, BitmapCreateOptions.IgnoreColorProfile, BitmapCacheOption.Default);
                     bm = (BitmapMetadata)bmpdecoder.Frames[0].Metadata.Clone();
                     break;
                 case ".gif":
                     gifdecoder = new GifBitmapDecoder(foto, BitmapCreateOptions.IgnoreColorProfile, BitmapCacheOption.Default);
                     bm = (BitmapMetadata)gifdecoder.Frames[0].Metadata.Clone();
                     break;
                 case ".ico":
                     icondecoder = new IconBitmapDecoder(foto, BitmapCreateOptions.IgnoreColorProfile, BitmapCacheOption.Default);
                     bm = (BitmapMetadata)icondecoder.Frames[0].Metadata.Clone();
                     break;
                 case ".tiff":
                     tiffdecoder = new TiffBitmapDecoder(foto, BitmapCreateOptions.IgnoreColorProfile, BitmapCacheOption.Default);
                     bm = (BitmapMetadata)tiffdecoder.Frames[0].Metadata.Clone();
                     break;
                 case ".wmp":
                     wmpdecoder = new WmpBitmapDecoder(foto, BitmapCreateOptions.IgnoreColorProfile, BitmapCacheOption.Default);
                     bm = (BitmapMetadata)wmpdecoder.Frames[0].Metadata.Clone();
                     break;
             }
             creationTime = Convert.ToDateTime(bm.DateTaken);
         }
     }
     catch (Exception ex) { WPF.MessageBox.Show(fileName + "\n" + ex.Message, "Decoder Exception"); }
 }
Exemple #22
0
        public Images()
        {
            using (Stream stream = Assembly.GetCallingAssembly().GetManifestResourceStream("Chess.Images.WhitePawn.png"))
            {
                PngBitmapDecoder decoder = new PngBitmapDecoder(stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
                this.WhitePawn = decoder.Frames[0];
            }

            using (Stream stream = Assembly.GetCallingAssembly().GetManifestResourceStream("Chess.Images.WhiteRook.png"))
            {
                PngBitmapDecoder decoder = new PngBitmapDecoder(stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
                this.WhiteRook = decoder.Frames[0];
            }

            using (Stream stream = Assembly.GetCallingAssembly().GetManifestResourceStream("Chess.Images.WhiteBishop.png"))
            {
                PngBitmapDecoder decoder = new PngBitmapDecoder(stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
                this.WhiteBishop = decoder.Frames[0];
            }

            using (Stream stream = Assembly.GetCallingAssembly().GetManifestResourceStream("Chess.Images.WhiteKnight.png"))
            {
                PngBitmapDecoder decoder = new PngBitmapDecoder(stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
                this.WhiteKnight = decoder.Frames[0];
            }

            using (Stream stream = Assembly.GetCallingAssembly().GetManifestResourceStream("Chess.Images.WhiteQueen.png"))
            {
                PngBitmapDecoder decoder = new PngBitmapDecoder(stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
                this.WhiteQueen = decoder.Frames[0];
            }

            using (Stream stream = Assembly.GetCallingAssembly().GetManifestResourceStream("Chess.Images.WhiteKing.png"))
            {
                PngBitmapDecoder decoder = new PngBitmapDecoder(stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
                this.WhiteKing = decoder.Frames[0];
            }

            using (Stream stream = Assembly.GetCallingAssembly().GetManifestResourceStream("Chess.Images.BlackPawn.png"))
            {
                PngBitmapDecoder decoder = new PngBitmapDecoder(stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
                this.BlackPawn = decoder.Frames[0];
            }

            using (Stream stream = Assembly.GetCallingAssembly().GetManifestResourceStream("Chess.Images.BlackRook.png"))
            {
                PngBitmapDecoder decoder = new PngBitmapDecoder(stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
                this.BlackRook = decoder.Frames[0];
            }

            using (Stream stream = Assembly.GetCallingAssembly().GetManifestResourceStream("Chess.Images.BlackBishop.png"))
            {
                PngBitmapDecoder decoder = new PngBitmapDecoder(stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
                this.BlackBishop = decoder.Frames[0];
            }

            using (Stream stream = Assembly.GetCallingAssembly().GetManifestResourceStream("Chess.Images.BlackKnight.png"))
            {
                PngBitmapDecoder decoder = new PngBitmapDecoder(stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
                this.BlackKnight = decoder.Frames[0];
            }

            using (Stream stream = Assembly.GetCallingAssembly().GetManifestResourceStream("Chess.Images.BlackQueen.png"))
            {
                PngBitmapDecoder decoder = new PngBitmapDecoder(stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
                this.BlackQueen = decoder.Frames[0];
            }

            using (Stream stream = Assembly.GetCallingAssembly().GetManifestResourceStream("Chess.Images.BlackKing.png"))
            {
                PngBitmapDecoder decoder = new PngBitmapDecoder(stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
                this.BlackKing = decoder.Frames[0];
            }

            using (Stream stream = Assembly.GetCallingAssembly().GetManifestResourceStream("Chess.Icon.ico"))
            {
                IconBitmapDecoder decoder = new IconBitmapDecoder(stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
                this.Icon = decoder.Frames[0];
            }
        }
Exemple #23
0
        /// <summary>
        /// Extracts a each image from an ico field.
        /// </summary>
        /// <param name="path">The path to the ico</param>
        /// <returns>Each image from inside the ico file</returns>
        public static List<ImageSource> GetIcoImages(string path)
        {
            List<ImageSource> ret = new List<ImageSource>();
            if (!path.StartsWith("pack://") && !path.Contains('\\') && !path.Contains('/'))
                path = "pack://application:,,,/Platform/Windows 7/GUI/Images/Icons/" + path + ".ico";
            var iconUri = new Uri(path, UriKind.RelativeOrAbsolute);
            try
            {
                var iconDecoder = new IconBitmapDecoder(iconUri,
                    BitmapCreateOptions.None, BitmapCacheOption.Default);

                // no image found
                if (iconDecoder.Frames.Count == 0) return ret;

                BitmapFrame largest = iconDecoder.Frames[0];
                foreach (BitmapFrame frame in iconDecoder.Frames)
                    ret.Add(frame);

                return ret;
            }
            catch (Exception)
            {
                return ret;
            }
        }
Exemple #24
0
        /// <summary>
        /// Get a frame from the icon with the given size.
        /// </summary>
        /// <returns>The requested frame.</returns>
        public ImageSource GetIconFrame(int width, int height)
        {
            if (_iconUri == null)
                return null;

            IconBitmapDecoder decoder = new IconBitmapDecoder(
                new Uri(_iconUri),
                BitmapCreateOptions.None,
                BitmapCacheOption.Default);

            foreach (BitmapFrame frame in decoder.Frames)
            {
                if (frame.PixelWidth == width && frame.PixelHeight == height)
                    return frame;
            }

            if (decoder.Frames.Count > 0)
                return decoder.Frames[0];

            return Icon;
        }
        internal static BitmapDecoder CreateFromUriOrStream(
            Uri baseUri,
            Uri uri,
            Stream stream,
            BitmapCreateOptions createOptions,
            BitmapCacheOption cacheOption,
            RequestCachePolicy uriCachePolicy,
            bool insertInDecoderCache
            )
        {
            Guid clsId = Guid.Empty;
            bool isOriginalWritable = false;
            SafeMILHandle decoderHandle = null;
            BitmapDecoder cachedDecoder = null;
            Uri finalUri = null;
            Stream uriStream = null;
            UnmanagedMemoryStream unmanagedMemoryStream = null;
            SafeFileHandle safeFilehandle = null;

            // check to ensure that images are allowed in partial trust
            DemandIfImageBlocked();

            if (uri != null)
            {
                finalUri = (baseUri != null) ?
                               System.Windows.Navigation.BaseUriHelper.GetResolvedUri(baseUri, uri) :
                               uri;

                if (insertInDecoderCache)
                {
                    if ((createOptions & BitmapCreateOptions.IgnoreImageCache) != 0)
                    {
                        ImagingCache.RemoveFromDecoderCache(finalUri);
                    }

                    cachedDecoder = CheckCache(
                        finalUri,
                        out clsId
                        );
                }
            }

            // try to retrieve the cached decoder
            if (cachedDecoder != null)
            {
                decoderHandle = cachedDecoder.InternalDecoder;
            }
            else if ((finalUri != null) && (finalUri.IsAbsoluteUri) && (stream == null) &&
                     ((finalUri.Scheme == Uri.UriSchemeHttp) ||
                      (finalUri.Scheme == Uri.UriSchemeHttps)))
            {
                return new LateBoundBitmapDecoder(baseUri, uri, stream, createOptions, cacheOption, uriCachePolicy);
            }
            else if ((stream != null) && (!stream.CanSeek))
            {
                return new LateBoundBitmapDecoder(baseUri, uri, stream, createOptions, cacheOption, uriCachePolicy);
            }
            else
            {
                // Create an unmanaged decoder
                decoderHandle = BitmapDecoder.SetupDecoderFromUriOrStream(
                    finalUri,
                    stream,
                    cacheOption,
                    out clsId,
                    out isOriginalWritable,
                    out uriStream,
                    out unmanagedMemoryStream,
                    out safeFilehandle
                    );
            }

            BitmapDecoder decoder = null;

            // Find out the decoder type and wrap it appropriately and return that
            if (MILGuidData.GUID_ContainerFormatBmp == clsId)
            {
                decoder = new BmpBitmapDecoder(
                    decoderHandle,
                    cachedDecoder,
                    baseUri,
                    uri,
                    stream,
                    createOptions,
                    cacheOption,
                    insertInDecoderCache,
                    isOriginalWritable,
                    uriStream,
                    unmanagedMemoryStream,
                    safeFilehandle
                    );
            }
            else if (MILGuidData.GUID_ContainerFormatGif == clsId)
            {
                decoder = new GifBitmapDecoder(
                    decoderHandle,
                    cachedDecoder,
                    baseUri,
                    uri,
                    stream,
                    createOptions,
                    cacheOption,
                    insertInDecoderCache,
                    isOriginalWritable,
                    uriStream,
                    unmanagedMemoryStream,
                    safeFilehandle
                    );
            }
            else if (MILGuidData.GUID_ContainerFormatIco == clsId)
            {
                decoder = new IconBitmapDecoder(
                    decoderHandle,
                    cachedDecoder,
                    baseUri,
                    uri,
                    stream,
                    createOptions,
                    cacheOption,
                    insertInDecoderCache,
                    isOriginalWritable,
                    uriStream,
                    unmanagedMemoryStream,
                    safeFilehandle
                    );
            }
            else if (MILGuidData.GUID_ContainerFormatJpeg == clsId)
            {
                decoder = new JpegBitmapDecoder(
                    decoderHandle,
                    cachedDecoder,
                    baseUri,
                    uri,
                    stream,
                    createOptions,
                    cacheOption,
                    insertInDecoderCache,
                    isOriginalWritable,
                    uriStream,
                    unmanagedMemoryStream,
                    safeFilehandle
                    );
            }
            else if (MILGuidData.GUID_ContainerFormatPng == clsId)
            {
                decoder = new PngBitmapDecoder(
                    decoderHandle,
                    cachedDecoder,
                    baseUri,
                    uri,
                    stream,
                    createOptions,
                    cacheOption,
                    insertInDecoderCache,
                    isOriginalWritable,
                    uriStream,
                    unmanagedMemoryStream,
                    safeFilehandle
                    );
            }
            else if (MILGuidData.GUID_ContainerFormatTiff == clsId)
            {
                decoder = new TiffBitmapDecoder(
                    decoderHandle,
                    cachedDecoder,
                    baseUri,
                    uri,
                    stream,
                    createOptions,
                    cacheOption,
                    insertInDecoderCache,
                    isOriginalWritable,
                    uriStream,
                    unmanagedMemoryStream,
                    safeFilehandle
                    );
            }
            else if (MILGuidData.GUID_ContainerFormatWmp == clsId)
            {
                decoder = new WmpBitmapDecoder(
                    decoderHandle,
                    cachedDecoder,
                    baseUri,
                    uri,
                    stream,
                    createOptions,
                    cacheOption,
                    insertInDecoderCache,
                    isOriginalWritable,
                    uriStream,
                    unmanagedMemoryStream,
                    safeFilehandle
                    );
            }
            else
            {
                decoder = new UnknownBitmapDecoder(
                    decoderHandle,
                    cachedDecoder,
                    baseUri,
                    uri,
                    stream,
                    createOptions,
                    cacheOption,
                    insertInDecoderCache,
                    isOriginalWritable,
                    uriStream,
                    unmanagedMemoryStream,
                    safeFilehandle
                    );
            }

            return decoder;
        }
Exemple #26
0
        private System.Windows.Media.ImageSource GetIcon(string ico)
        {

            // We'll look for our icons in the folder of the assembly

            // (we could also use a resources, of course)



            string path =

              Path.GetDirectoryName(

                Assembly.GetExecutingAssembly().Location

              );



            // Check our .ico file exists



            string fileName = path + "\\" + ico;

            if (File.Exists(fileName))
            {

                // Get access to it via a stream



                Stream fs =

                  new FileStream(

                    fileName,

                    FileMode.Open,

                    FileAccess.Read,

                    FileShare.Read

                  );

                using (fs)
                {

                    // Decode the contents and return them



                    IconBitmapDecoder dec =

                      new IconBitmapDecoder(

                        fs,

                        BitmapCreateOptions.PreservePixelFormat,

                        BitmapCacheOption.Default

                      );

                    return dec.Frames[0];

                }

            }

            return null;

        }
        private static BitmapSource Load(object obj, BitmapEncoding enc, 
            BitmapCreateOptions create, BitmapCacheOption cache, out BitmapMetadata data)
        {
            BitmapDecoder dec = null;

            if (obj is Stream)
            {
                Stream stream = obj as Stream;

                switch (enc)
                {
                    case BitmapEncoding.Bmp:
                        dec = new BmpBitmapDecoder(stream, create, cache);
                        break;
                    case BitmapEncoding.Png:
                        dec = new PngBitmapDecoder(stream, create, cache);
                        break;
                    case BitmapEncoding.Jpg:
                        dec = new JpegBitmapDecoder(stream, create, cache);
                        break;
                    case BitmapEncoding.Tiff:
                        dec = new TiffBitmapDecoder(stream, create, cache);
                        break;
                    case BitmapEncoding.Gif:
                        dec = new GifBitmapDecoder(stream, create, cache);
                        break;
                    case BitmapEncoding.Wmp:
                        dec = new WmpBitmapDecoder(stream, create, cache);
                        break;
                    case BitmapEncoding.Icon:
                        dec = new IconBitmapDecoder(stream, create, cache);
                        break;
                    default:
                        throw new NotImplementedException();
                }
            }
            else if (obj is Uri)
            {
                Uri stream = obj as Uri;

                switch (enc)
                {
                    case BitmapEncoding.Bmp:
                        dec = new BmpBitmapDecoder(stream, create, cache);
                        break;
                    case BitmapEncoding.Png:
                        dec = new PngBitmapDecoder(stream, create, cache);
                        break;
                    case BitmapEncoding.Jpg:
                        dec = new JpegBitmapDecoder(stream, create, cache);
                        break;
                    case BitmapEncoding.Tiff:
                        dec = new TiffBitmapDecoder(stream, create, cache);
                        break;
                    case BitmapEncoding.Gif:
                        dec = new GifBitmapDecoder(stream, create, cache);
                        break;
                    case BitmapEncoding.Wmp:
                        dec = new WmpBitmapDecoder(stream, create, cache);
                        break;
                    case BitmapEncoding.Icon:
                        dec = new IconBitmapDecoder(stream, create, cache);
                        break;
                    default:
                        throw new NotImplementedException();
                }
            }
            else
                throw new ArgumentException();

            data = dec.Metadata;
            return dec.Frames[0];
        }
        public StickyWindowModel(string DeSerializeXML)
        {
            this.Name = String.Format("stickyWindow_{0}", DateTime.Now.Ticks.ToString());
            this.MinHeight = 50;
            this.MinWidth = 100;
            this.MaxHeight = 600;
            this.MaxWidth = 600;
            this.MyWindowState = WindowState.Normal;
            this.Background = Brushes.Transparent;
            this.AllowsTransparency = true;
            this.WindowStyle = WindowStyle.None;
            this.Title = "stickyWindow";
            this.ShowInTaskbar = false;

            IconBitmapDecoder icon = new IconBitmapDecoder(iconUri, BitmapCreateOptions.None, BitmapCacheOption.Default);
            this.Icon = icon.Frames[0];

            this.Show();

            if (DeSerializeXML != null)
                Deserialize(DeSerializeXML);
            else
            {
                this.color = Colors.LightBlue;
                this.textColor = Colors.Black;
                Size oSize = new Size(200, 200);
                this.OriginalSize = oSize;
            }

            #region Event/Bindings Wireup

            this.SetContainerCanvasBindings(SetBindingMode.SetBinding);
            this.sSlider.MouseEnter += new MouseEventHandler(slider_MouseEnter);
            this.sSlider.MouseLeave += new MouseEventHandler(slider_MouseLeave);
            this.AddHandler(ScrollViewer.ScrollChangedEvent, new RoutedEventHandler(scroller_ScrollChanged));
            this.sContextCircle.MouseLeftButtonDown += new MouseButtonEventHandler(contextCircle_MouseLeftButtonDown);
            //this.sTextArea.LostKeyboardFocus += new KeyboardFocusChangedEventHandler(txt_LostKeyboardFocus);
            //this.sTextArea.MouseDoubleClick += new MouseButtonEventHandler(txt_MouseDoubleClick);
            this.MouseLeftButtonDown += new MouseButtonEventHandler(StickyWindowModel_MouseLeftButtonDown);
            SetContextCircleMouseEventBindings(SetBindingMode.SetBinding);

            #endregion

            #region CommandBindings

            StickyWindowCommands commands = new StickyWindowCommands(this);
            this.sContextCircle.ContextMenu = commands.GetContextMenu();
            CommandBinding CloseCmdBinding = new CommandBinding(CloseCmd, commands.CloseCmdExecuted, commands.CloseCmdCanExecute);
            CommandBinding MinimizeCmdBinding = new CommandBinding(MinimizeCmd, commands.MinizmizeCmdExecuted, commands.MinizmizeCmdCanExecute);
            CommandBinding FitContentCmdBinding = new CommandBinding(FitContentCmd, commands.FitContentCmdExecuted, commands.FitContentCmdCanExecute);
            CommandBinding RestoreCmdBinding = new CommandBinding(RestoreCmd, commands.RestoreCmdExecuted, commands.RestoreCmdCanExecute);
            CommandBinding PrintCmdBinding = new CommandBinding(PrintCmd, commands.PrintCmdExecuted, commands.PrintCmdCanExecute);
            CommandBinding ColorsCmdBinding = new CommandBinding(ColorsCmd, commands.ColorsCmdExecuted, commands.ColorsCmdCanExecute);

            this.CommandBindings.Add(CloseCmdBinding);
            this.CommandBindings.Add(MinimizeCmdBinding);
            this.CommandBindings.Add(FitContentCmdBinding);
            this.CommandBindings.Add(RestoreCmdBinding);
            this.CommandBindings.Add(PrintCmdBinding);
            this.CommandBindings.Add(ColorsCmdBinding);

            #endregion

            this.Opacity = 1;
        }
		private void channelsControl_OnStreamOpen(object sender, StreamOpenEventArgs e)
		{
			if (e != null && !string.IsNullOrEmpty(e.ChannelName) && !isStreamVisible(e.ChannelName))
			{
				Utility.GetAccessToken(user);

				try
				{
					if (!string.IsNullOrEmpty(user.AccessToken) && !string.IsNullOrEmpty(user.Name))
					{
						if (userOptions.ShowEmoticonsInChat && emoticons == null)
						{
							emoticons = DataFileManager.GetEmoticons();
						}

						visibleStreams.Add(e.ChannelName);

						if (userOptions.OpenStreamsInNewTab)
						{
							var stream = new Stream(user,
								e.ChannelName,
								user.AccessToken,
								potentialNicknameColors,
								streamTitleAutoCompleteOptions,
								streamGameAutoCompleteOptions,
								emoticons);

							var tab = new ClosableTab
							{
								Title = e.ChannelName,
								VerticalContentAlignment = VerticalAlignment.Stretch,
								Content = stream
							};

							tab.Closed += delegate
							{
								visibleStreams.Remove(e.ChannelName);
								stream.Disconnect();
							};

							mainTabs.Items.Add(tab);
						}
						else
						{
							var stream = new Stream(user,
								e.ChannelName,
								user.AccessToken,
								potentialNicknameColors,
								streamTitleAutoCompleteOptions,
								streamGameAutoCompleteOptions,
								emoticons);

							var ibd =
								new IconBitmapDecoder(new Uri("pack://application:,,,/LivestreamBuddyNew;component/livestream-ICON.ico"),
									BitmapCreateOptions.None, BitmapCacheOption.Default);
							var brush = new LinearGradientBrush((Color) ColorConverter.ConvertFromString("#FF515151"), Colors.LightGray,
								new Point(.5, 0), new Point(.5, 1));

							var newWindow = new Window
							{
								Width = 525,
								MinWidth = 525,
								Height = 675,
								MinHeight = 675,
								Title = e.ChannelName,
								Icon = ibd.Frames[0],
								Background = brush,
								Content = new Border {Padding = new Thickness(13, 13, 13, 13), Child = stream}
							};

							newWindow.Closed += delegate
							{
								visibleStreams.Remove(e.ChannelName);
								stream.Disconnect();
							};

							newWindow.Show();
						}
					}
					else
					{
						throw new Exception();
					}
				}
				catch
				{
					Utility.ClearUserData(user);
					MessageBox.Show("Something went wrong. Try again.");
				}
			}
		}
		private void OptionsClick(object sender, RoutedEventArgs e)
		{
			var optionsControl = new Controls.Options();
			var ibd = new IconBitmapDecoder(new Uri("pack://application:,,,/LivestreamBuddyNew;component/livestream-ICON.ico"),
				BitmapCreateOptions.None, BitmapCacheOption.Default);
			var brush = new LinearGradientBrush((Color) ColorConverter.ConvertFromString("#FF515151"), Colors.LightGray,
				new Point(.5, 0), new Point(.5, 1));
			var newWindow = new Window
			{
				Width = 325,
				MinWidth = 325,
				Height = 375,
				MinHeight = 375,
				Title = "Options",
				Icon = ibd.Frames[0],
				Background = brush,
				Content = new Border {Padding = new Thickness(13, 13, 13, 13), Child = optionsControl}
			};

			optionsControl.OnSaved += delegate
			{
				userOptions = optionsControl.UserOptions;
				newWindow.Close();
			};

			newWindow.Show();
		}
        public static ImageSource GetIcon(string s)
        {
            System.Drawing.Icon icon = ManagedWinapi.ExtendedFileInfo.GetIconForFilename(s, false);
            if (icon == null) return null;
            using (MemoryStream ms = new MemoryStream())
            {
                icon.Save(ms);

                var dec = new IconBitmapDecoder(ms, BitmapCreateOptions.PreservePixelFormat,BitmapCacheOption.Default);
                return dec.Frames[0];
            }
        }
        private static void ensureIconsInitialised()
        {
            if (iconActive != null)
            {
                return;
            }

            iconActive = loadIconFromResource("toggl");
            iconInactive = loadIconFromResource("toggl_inactive");
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="serviceProvider"></param>
        /// <returns></returns>
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            Assembly caller = Assembly.GetEntryAssembly();
            var obj = caller.GetType(ClassName).GetProperty(ResourceName, BindingFlags.Static | BindingFlags.NonPublic);
            if (obj != null)
            {
                var val = obj.GetValue(obj, null);
                if (val != null)
                {
                    MemoryStream mstr = new MemoryStream();
                    BitmapDecoder decoder = null;

                    if (val is Icon)
                    {
                        ((Icon)val).Save(mstr);
                        decoder = new IconBitmapDecoder(mstr, BitmapCreateOptions.None, BitmapCacheOption.None);

                    }
                    else if (val is Bitmap)
                    {
                        Bitmap bmp = val as Bitmap;
                        if (ImageFormat == ImageFormat.Png)
                        {
                            bmp.Save(mstr, ImageFormat.Png);
                            decoder = new PngBitmapDecoder(mstr, BitmapCreateOptions.None, BitmapCacheOption.None);
                        }
                        else if (ImageFormat == ImageFormat.Tiff)
                        {
                            bmp.Save(mstr, ImageFormat.Tiff);
                            decoder = new TiffBitmapDecoder(mstr, BitmapCreateOptions.None, BitmapCacheOption.None);
                        }
                        else if (ImageFormat == ImageFormat.Gif)
                        {
                            bmp.Save(mstr, ImageFormat.Gif);
                            decoder = new GifBitmapDecoder(mstr, BitmapCreateOptions.None, BitmapCacheOption.None);
                        }
                        else if (ImageFormat == ImageFormat.Jpeg)
                        {
                            bmp.Save(mstr, ImageFormat.Jpeg);
                            decoder = new JpegBitmapDecoder(mstr, BitmapCreateOptions.None, BitmapCacheOption.None);
                        }
                        else if (ImageFormat == ImageFormat.Bmp)
                        {
                            bmp.Save(mstr, ImageFormat.Bmp);
                            decoder = new BmpBitmapDecoder(mstr, BitmapCreateOptions.None, BitmapCacheOption.None);
                        }
                    }

                    if (decoder != null)
                    {
                        return decoder.Frames[0];
                    }
                }

                return null;
            }
            else
            {
                return null;
            }
        }