public FileNode(string path) { if (!File.Exists(path)) throw new FileNotFoundException("The file added to MediaFile was not found.", path); _fileIcon = null; _path = path; FileInfo fileInfo = new FileInfo(_path); _name = fileInfo.Name; _sizeOnDisc = fileInfo.Length; // // Get the File icon // Shell.SHFILEINFO shinfo = new Shell.SHFILEINFO(); IntPtr hImg = Shell.SHGetFileInfo(_path, 0, ref shinfo, (uint)Marshal.SizeOf(shinfo), Shell.SHGFI_ICON | Shell.SHGFI_SMALLICON); if (shinfo.hIcon != null) { //The icon is returned in the hIcon member of the shinfo struct System.Drawing.IconConverter imageConverter = new System.Drawing.IconConverter(); System.Drawing.Icon icon = System.Drawing.Icon.FromHandle(shinfo.hIcon); try { _fileIcon = (System.Drawing.Image)imageConverter.ConvertTo(icon, typeof(System.Drawing.Image)); } catch (NotSupportedException) { } Shell.DestroyIcon(shinfo.hIcon); } }
static void Main(string[] args) { string inFilename = args[0]; string outFilename = args[1]; Bitmap bitmap = new Bitmap(inFilename); IconConverter convertor = new IconConverter(); Icon icon = Icon.FromHandle(bitmap.GetHicon()); FileStream fs = new FileStream(outFilename, FileMode.Create); icon.Save(fs); fs.Close(); Console.WriteLine("Done."); }
public DirectoryNode(string path) { if (!Directory.Exists(path)) { throw new FileNotFoundException("The directory added to MediaDirectory was not found.", path); } _path = path; _nodes = new List <IMediaNode>(); _name = new FileInfo(_path).Name; string[] files = Directory.GetFiles(_path); foreach (string file in files) { _nodes.Add(new FileNode(file)); } string[] directories = Directory.GetDirectories(_path); foreach (string directory in directories) { _nodes.Add(new DirectoryNode(directory)); } _sizeOnDisc = 0; foreach (IMediaNode node in _nodes) { _sizeOnDisc += node.SizeOnDisc; } // // Get the Directory icon // Shell.SHFILEINFO shinfo = new Shell.SHFILEINFO(); IntPtr hImg = Shell.SHGetFileInfo(_path, 0, ref shinfo, (uint)Marshal.SizeOf(shinfo), Shell.SHGFI_ICON | Shell.SHGFI_SMALLICON); if (shinfo.hIcon != null) { //The icon is returned in the hIcon member of the shinfo struct System.Drawing.IconConverter imageConverter = new System.Drawing.IconConverter(); System.Drawing.Icon icon = System.Drawing.Icon.FromHandle(shinfo.hIcon); try { _fileIcon = (System.Drawing.Image)imageConverter.ConvertTo(icon, typeof(System.Drawing.Image)); } catch (NotSupportedException) { } Shell.DestroyIcon(shinfo.hIcon); } }
/// <summary> /// 根据Exe文件的名称,从服务器读取这个文件的图标,失败返回null; /// </summary> internal System.Drawing.Icon GetExeIconFromServer(string FullPath, bool isLarge) { string str = this.TCPString("2BackIcon$0:" + FullPath + ":" + isLarge.ToString() + ":0"); if (str.StartsWith("Error")) { return(null); } else { byte[] btArr = System.Text.Encoding.ASCII.GetBytes(str); System.Drawing.IconConverter icc = new System.Drawing.IconConverter(); System.Drawing.Icon _icon = icc.ConvertFrom(btArr) as System.Drawing.Icon; return(_icon); } }
public DirectoryNode(string path) { if (!Directory.Exists(path)) throw new FileNotFoundException("The directory added to MediaDirectory was not found.", path); _path = path; _nodes = new List<IMediaNode>(); _name = new FileInfo(_path).Name; string[] files = Directory.GetFiles(_path); foreach (string file in files) _nodes.Add(new FileNode(file)); string[] directories = Directory.GetDirectories(_path); foreach (string directory in directories) _nodes.Add(new DirectoryNode(directory)); _sizeOnDisc = 0; foreach (IMediaNode node in _nodes) _sizeOnDisc += node.SizeOnDisc; // // Get the Directory icon // Shell.SHFILEINFO shinfo = new Shell.SHFILEINFO(); IntPtr hImg = Shell.SHGetFileInfo(_path, 0, ref shinfo, (uint)Marshal.SizeOf(shinfo), Shell.SHGFI_ICON | Shell.SHGFI_SMALLICON); if (shinfo.hIcon != null) { //The icon is returned in the hIcon member of the shinfo struct System.Drawing.IconConverter imageConverter = new System.Drawing.IconConverter(); System.Drawing.Icon icon = System.Drawing.Icon.FromHandle(shinfo.hIcon); try { _fileIcon = (System.Drawing.Image)imageConverter.ConvertTo(icon, typeof(System.Drawing.Image)); } catch (NotSupportedException) { } Shell.DestroyIcon(shinfo.hIcon); } }
public FileNode(string path) { if (!File.Exists(path)) { throw new FileNotFoundException("The file added to MediaFile was not found.", path); } _fileIcon = null; _path = path; FileInfo fileInfo = new FileInfo(_path); _name = fileInfo.Name; _sizeOnDisc = fileInfo.Length; // // Get the File icon // Shell.SHFILEINFO shinfo = new Shell.SHFILEINFO(); IntPtr hImg = Shell.SHGetFileInfo(_path, 0, ref shinfo, (uint)Marshal.SizeOf(shinfo), Shell.SHGFI_ICON | Shell.SHGFI_SMALLICON); if (shinfo.hIcon != null) { //The icon is returned in the hIcon member of the shinfo struct System.Drawing.IconConverter imageConverter = new System.Drawing.IconConverter(); System.Drawing.Icon icon = System.Drawing.Icon.FromHandle(shinfo.hIcon); try { _fileIcon = (System.Drawing.Image)imageConverter.ConvertTo(icon, typeof(System.Drawing.Image)); } catch (NotSupportedException) { } Shell.DestroyIcon(shinfo.hIcon); } }
public void SetUp () { icon = new Icon (TestBitmap.getInFile ("bitmaps/VisualPng.ico")); iconStr = icon.ToString (); icoConv = new IconConverter(); icoConvFrmTD = (IconConverter) TypeDescriptor.GetConverter (icon); Stream stream = new FileStream (TestBitmap.getInFile ("bitmaps/VisualPng1.ico"), FileMode.Open); int length = (int) stream.Length; iconBytes = new byte [length]; try { if (stream.Read (iconBytes, 0, length) != length) Assert.Fail ("SU#1: Read Failure"); } catch (Exception e) { Assert.Fail ("SU#2 Exception thrown while reading. Exception is: "+e.Message); } finally { stream.Close (); } stream.Close (); }
private void Form1_Load(object sender, EventArgs e) { tunes = new TunesRemote(this); tunes.DoPair(); tunes.Login(); List<Playlist> lists = tunes.playlists; foreach (Playlist list in lists) { cmbPlaylist.Items.Add(list); if (list.id == tunes.DJID) cmbPlaylist.SelectedItem = list; } tunes.Status(); tunes.GetPlaylist(tunes.DJID); tmrRefresh.Start(); Notify.Tag = this; System.Drawing.IconConverter ic = new System.Drawing.IconConverter(); pauseIco = Icon.FromHandle(Properties.Resources.pause.GetHicon()); playIco = Icon.FromHandle(Properties.Resources.play.GetHicon()); btnPrevThumb = new Microsoft.WindowsAPICodePack.Taskbar.ThumbnailToolBarButton(Icon.FromHandle(Properties.Resources.prev.GetHicon()), "Previous"); btnPrevThumb.Click += new EventHandler<Microsoft.WindowsAPICodePack.Taskbar.ThumbnailButtonClickedEventArgs>(btnPrev_Click); btnPlayThumb = new Microsoft.WindowsAPICodePack.Taskbar.ThumbnailToolBarButton(pauseIco, "Play/Pause"); btnPlayThumb.Click += new EventHandler<Microsoft.WindowsAPICodePack.Taskbar.ThumbnailButtonClickedEventArgs>(btnPP_Click); btnNextThumb = new Microsoft.WindowsAPICodePack.Taskbar.ThumbnailToolBarButton(Icon.FromHandle(Properties.Resources.next.GetHicon()), "Next"); btnNextThumb.Click += new EventHandler<Microsoft.WindowsAPICodePack.Taskbar.ThumbnailButtonClickedEventArgs>(btnNext_Click); Microsoft.WindowsAPICodePack.Taskbar.TaskbarManager.Instance.ThumbnailToolBars.AddButtons(this.Handle, btnPrevThumb, btnPlayThumb, btnNextThumb); tmrTick.Start(); }