public static Icon Extrfile(String namefile) { var shell = (ShellFile)ShellObject.FromParsingName(namefile); ShellThumbnail sh = shell.Thumbnail; return(sh.Icon); }
public DeviceClassFolder(DeviceManagerFolder parent, Guid classGuid) : base(parent, new GuidKeyShellItemId(classGuid)) { ClassGuid = classGuid; // come up with the display name for class var sb = new StringBuilder(1024); var size = sb.Capacity; SetupDiGetClassDescription(classGuid, sb, sb.Capacity, ref size); DisplayName = sb.ToString(); var iconIndex = GetIconPath(out var iconPath); if (iconIndex.HasValue && iconPath != null) { Thumbnail = new ShellThumbnail(NormalizeIconPath(iconPath), iconIndex.Value); } // remove default columns we don't need here RemoveColumn(Props.System.ItemType); RemoveColumn(Props.System.Size); RemoveColumn(Props.System.DateModified); RemoveColumn(Props.System.PerceivedType); RemoveColumn(Props.System.Kind); // add these ones, already defined by Windows AddColumn(Props.System.Devices.DeviceInstanceId, SHCOLSTATE.SHCOLSTATE_ONBYDEFAULT); AddColumn(Props.System.Devices.ClassGuid, SHCOLSTATE.SHCOLSTATE_ONBYDEFAULT); AddColumn(Props.System.Devices.ContainerId, SHCOLSTATE.SHCOLSTATE_ONBYDEFAULT); }
private static BitmapSource getShellThumbnail(object fileName) { int pixelWidth = 150; int pixelHeight = 120;//todo: sta thread try { using (var st = new ShellThumbnail { DesiredSize = new System.Drawing.Size(pixelWidth, pixelHeight) }) { using (var pic = st.GetThumbnail(fileName.ToString())) { return(Imaging.CreateBitmapSourceFromHBitmap( pic.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromWidthAndHeight(pixelWidth, pixelHeight))); } } } catch (Exception ex) { //todo: log ... } return(null); }
public static Icon Extracticonfile(String namefile) { var shell = ShellObject.FromParsingName(namefile); ShellThumbnail sh = shell.Thumbnail; return(sh.MediumIcon); }
/// <summary> /// Get the icon image with overlay icon image. /// </summary> /// <param name="thumbnail"><see cref="ShellThumbnail" />.</param> /// <param name="updateImageSource">Update action.</param> /// <returns></returns> public static async Task GetDefaultIconWithOverlayAsync(ShellThumbnail thumbnail, Action <ImageSource> updateImageSource) { Contract.Requires <ArgumentNullException>(thumbnail != null); var bitmapSource = await GetIconWithOverlayBitmapSourceAsync(thumbnail); updateImageSource.Invoke(bitmapSource); }
private void GerarThumbnailDoArquivo(string caminhoArquivo) { ShellFile shellFile = ShellFile.FromFilePath(caminhoArquivo); ShellThumbnail thumbnail = shellFile.Thumbnail; Image image = thumbnail.LargeBitmap; PictureBoxHidraulica.Image = image; PictureBoxHidraulica.SizeMode = PictureBoxSizeMode.StretchImage; }
public static Icon Extract(String st) { //var icon = Icon.ExtractAssociatedIcon(icons); //return icon; var shellobject = (ShellFolder)ShellObject.FromParsingName(st); ShellThumbnail shellt = shellobject.Thumbnail; return(shellt.Icon); }
public XmlAttributeShellItem(ShellFolder parent, XmlAttribute attribute) : base(parent, new StringKeyShellItemId(attribute.LocalName)) { Attribute = attribute; DisplayName = attribute.LocalName; var iconsPath = ((RootFolder)parent.Root).Server.IconsDllPath; // note the icon index syntax: the index must be negative when passed to the Windows Shell Thumbnail = new ShellThumbnail(iconsPath, -LocalShellFolderServer.AttributeIconIndex); }
public static Bitmap GetTransparentBitmap(this ShellThumbnail shellThumbnail, ShellThumbnailSize shellThumbnailSize = ShellThumbnailSize.Default) { return(shellThumbnailSize switch { ShellThumbnailSize.Default => CreateAlphaBitmap(shellThumbnail.Bitmap, PixelFormat.Format32bppArgb), ShellThumbnailSize.Small => CreateAlphaBitmap(shellThumbnail.SmallBitmap, PixelFormat.Format32bppArgb), ShellThumbnailSize.Medium => CreateAlphaBitmap(shellThumbnail.MediumBitmap, PixelFormat.Format32bppArgb), ShellThumbnailSize.Large => CreateAlphaBitmap(shellThumbnail.LargeBitmap, PixelFormat.Format32bppArgb), ShellThumbnailSize.ExtraLarge => CreateAlphaBitmap(shellThumbnail.ExtraLargeBitmap, PixelFormat.Format32bppArgb), _ => CreateAlphaBitmap(shellThumbnail.Bitmap, PixelFormat.Format32bppArgb) });
/// <summary> /// Load the thumbnail image source from <see cref="ShellThumbnail" /> /// and invoke <paramref name="updateImageSource" /> action. /// </summary> /// <param name="thumbnail"><see cref="ShellThumbnail" />.</param> /// <param name="updateImageSource">Update action.</param> /// <returns></returns> public static async Task LoadAsync(ShellThumbnail thumbnail, Action <ImageSource> updateImageSource) { Contract.Requires <ArgumentNullException>(thumbnail != null); await GetDefaultIconAsync(thumbnail, updateImageSource); await GetDefaultIconWithOverlayAsync(thumbnail, updateImageSource); if (thumbnail.OriginalWidth >= 32) { await GetThumbnailAsync(thumbnail, updateImageSource); } }
private static Task <BitmapSource> GetThumbnailBitmapSourceAsync(ShellThumbnail thumbnail) { Contract.Requires(thumbnail != null); return(Application.Current.Dispatcher.InvokeAsync(() => System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap( thumbnail.ImageHandle, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()) ).Task); }
private void Form1_Load(object sender, EventArgs e) { string fileName = @"\\PC\Users\Public\bitmap.bmp"; ShellFile shellFile = ShellFile.FromFilePath(fileName); ShellThumbnail thumbnail = shellFile.Thumbnail; var pictureBox = new PictureBox { Image = thumbnail.Bitmap, Dock = DockStyle.Fill }; Controls.Add(pictureBox); }
private void GerarThumbnailDoArquivo(string caminhoArquivo) { //Image.GetThumbnailImageAbort callback = new Image.GetThumbnailImageAbort(ThumbnailCallback); //Image image = new Bitmap(caminhoArquivo); //Image image = Image.FromFile(caminhoArquivo); //Image pThumbnail = image.GetThumbnailImage(200, 160, callback, IntPtr.Zero); ShellFile shellFile = ShellFile.FromFilePath(caminhoArquivo); ShellThumbnail thumbnail = shellFile.Thumbnail; Image image = thumbnail.Bitmap; PictureBoxEletrica.Image = image; PictureBoxEletrica.SizeMode = PictureBoxSizeMode.StretchImage; }
private static Task <BitmapSource> GetIconWithOverlayBitmapSourceAsync(ShellThumbnail thumbnail) { Contract.Requires(thumbnail != null); return(Application.Current.Dispatcher.InvokeAsync(() => { using (var imageList = new ShellImageList(GetSizeOption(thumbnail))) { using (var icon = imageList.GetIcon(thumbnail.IconIndex, thumbnail.OverlayIndex)) { return ShellIconFactory.CreateBitmapSource(icon); } } }).Task); }
/// <summary> /// Get the thumbnail image size option. /// </summary> /// <returns></returns> private static int GetSizeOption(ShellThumbnail thumbnail) { var width = thumbnail.OriginalWidth; if (width <= 16) { return(ImageListTypes.SHIL_SMALL); } else if (width <= 32) { return(ImageListTypes.SHIL_LARGE); } else if (width <= 48) { return(ImageListTypes.SHIL_EXTRALARGE); } return(ImageListTypes.SHIL_JUMBO); }
/// <summary> /// Gets a transparent bitmap icon or thumbnail from a <see cref="ShellThumbnail"/> based on size /// </summary> /// <param name="shellThumbnail">The shell thumbnail to get the bitmap from</param> /// <param name="shellThumbnailSize">The size of the thumbnail or icon to retrieve</param> /// <returns>The thumbnail or icon</returns> public static Bitmap GetTransparentBitmap(this ShellThumbnail shellThumbnail, ShellThumbnailSize shellThumbnailSize = ShellThumbnailSize.Default) { switch (shellThumbnailSize) { default: case ShellThumbnailSize.Default: return(CreateAlphaBitmap(shellThumbnail.Bitmap, PixelFormat.Format32bppArgb)); case ShellThumbnailSize.Small: return(CreateAlphaBitmap(shellThumbnail.SmallBitmap, PixelFormat.Format32bppArgb)); case ShellThumbnailSize.Medium: return(CreateAlphaBitmap(shellThumbnail.MediumBitmap, PixelFormat.Format32bppArgb)); case ShellThumbnailSize.Large: return(CreateAlphaBitmap(shellThumbnail.LargeBitmap, PixelFormat.Format32bppArgb)); case ShellThumbnailSize.ExtraLarge: return(CreateAlphaBitmap(shellThumbnail.ExtraLargeBitmap, PixelFormat.Format32bppArgb)); }
/// <summary> /// Miniatura (Thumbnail Handlers) /// </summary> /// <param name="file"></param> /// <param name="amplitud"></param> /// <param name="altura"></param> /// <returns> si hay algun problema devuelve null</returns> public static Bitmap Miniatura(this FileInfo file, int amplitud, int altura) { Bitmap bmp = null; ShellThumbnail thub = new ShellThumbnail(); try { bmp = thub.GetThumbnail(file.FullName, amplitud, altura).Clone() as Bitmap; } catch { try { bmp = file.Icono(); } catch { bmp = null; } } return(bmp); }
private void frmMain_Load(object sender, EventArgs e) { lblVersion.Text = $"{Assembly.GetExecutingAssembly().GetName().Version.ToString()}"; MediaInfo MI = new MediaInfo(); MI.Open(file); MI.Option("Complete", "0"); foreach (var line in Regex.Split(MI.Inform(), "\r\n")) { if (line.IndexOf("General") == 0 || line.IndexOf("Video") == 0 || line.IndexOf("Audio") == 0 || line.IndexOf("Text") == 0 || line.IndexOf("Other") == 0 || line.IndexOf("Image") == 0 || line.IndexOf("Menu") == 0) { rtbInfo.SelectionFont = new Font(rtbInfo.SelectionFont.FontFamily, 10f, FontStyle.Bold); rtbInfo.SelectionColor = Color.FromArgb(255, 51, 153); rtbInfo.SelectedText = line + "\r\n"; } else { rtbInfo.SelectionColor = Color.Black; rtbInfo.SelectedText += line + "\r\n"; } } MI.Close(); ShellFile shellFile = ShellFile.FromFilePath(file); ShellThumbnail thumbnail = shellFile.Thumbnail; picThumbnail.Image = thumbnail.Bitmap; lblFile.Text = Path.GetFileName(file); lblDateCreated.Text = "Created : " + new FileInfo(file).CreationTime.ToString(); lblDateModified.Text = "Modified : " + new FileInfo(file).LastWriteTime.ToString(); SetToolTip(lblFile, Path.GetFileName(file)); }
/// <summary> /// Set the <see cref="ShellThumbnail" />. /// </summary> /// <param name="thumbnail"><see cref="ShellThumbnail" />.</param> public void SetSource(ShellThumbnail thumbnail) { this.ShellThumbnail = thumbnail; }
public Bitmap ThumbnailForFile(string FilePath, ThumbnailSizes thumbSize, ref string txtLog) { if ( (!File.Exists(FilePath)) && (!Directory.Exists(FilePath)) ) { return(null); } if (ShellFile.IsPlatformSupported) { try { using (ShellFile sf = ShellFile.FromFilePath(FilePath)) { if (sf == null) { return(null); } ShellThumbnail thumb = sf.Thumbnail; if (thumb == null) { return(null); } switch (thumbSize) { case ThumbnailSizes.Medium: return(thumb.MediumBitmap); case ThumbnailSizes.Large: return(thumb.LargeBitmap); case ThumbnailSizes.ExtraLarge: return(thumb.ExtraLargeBitmap); default: //case ThumbnailSizes.Small: return(thumb.SmallBitmap); } } } catch { // Do not return; try legacy method } } // Use legacy method LegacyThumbnailExtractor2 tc = new LegacyThumbnailExtractor2(thumbSize); Bitmap bThumb = null; Bitmap bmpNew = null; bThumb = tc.GetThumbnail(FilePath); // No thumbnail returned - look for folder.jpg (for MP3s) if (bThumb != null) { bmpNew = (Bitmap)bThumb.Clone(); } else { // NB: use a new thumbnail extractor string stub = Path.GetDirectoryName(FilePath); string artworkFN = Path.Combine(stub, "folder.jpg"); txtLog += "Artwork FN: " + artworkFN + Environment.NewLine; if (File.Exists(artworkFN)) { bThumb = tc.GetThumbnail(artworkFN); if (bThumb != null) { bmpNew = (Bitmap)bThumb.Clone(); } } } return(bmpNew); }
public void ProcessRequest(HttpContext context) { hapConfig config = hapConfig.Current; User user = new User(); if (config.AD.AuthenticationMode == Web.Configuration.AuthMode.Forms) { HttpCookie token = HttpContext.Current.Request.Cookies["token"]; if (token == null) { throw new AccessViolationException("Token Cookie Missing, user not logged in correctly"); } user.Authenticate(HttpContext.Current.User.Identity.Name, TokenGenerator.ConvertToPlain(token.Value)); } user.ImpersonateContained(); try { Context = context; config = hapConfig.Current; DriveMapping unc; string path = Converter.DriveToUNC(RoutingPath.Replace('^', '&'), RoutingDrive, out unc, ((HAP.AD.User)Membership.GetUser())); FileInfo file = new FileInfo(path); Image thumb; try { Bitmap b = new ShellThumbnail().GetThumbnail(file.FullName); thumb = b;// FixedSize(b, 64, 64); if (thumb == null) { throw new NullReferenceException(); } } catch { FileStream fs = file.OpenRead(); Image image = Image.FromStream(fs); thumb = FixedSize(image, 64, 64); image.Dispose(); fs.Close(); fs.Dispose(); } MemoryStream m = new MemoryStream(); thumb.Save(m, ImageFormat.Png); context.Response.Clear(); context.Response.ExpiresAbsolute = DateTime.Now; context.Response.ContentType = Converter.MimeType(".png"); context.Response.Buffer = true; context.Response.AppendHeader("Content-Disposition", "inline; filename=\"" + file.Name + "\""); context.Response.AppendHeader("Content-Length", m.Length.ToString()); context.Response.Clear(); m.WriteTo(context.Response.OutputStream); context.Response.Flush(); file = null; user.EndContainedImpersonate(); } catch { DriveMapping unc; string path = Converter.DriveToUNC(RoutingPath.Replace('^', '&'), RoutingDrive, out unc, ((HAP.AD.User)Membership.GetUser())); FileInfo file = new FileInfo(path); string Icon = HAP.MyFiles.File.ParseForImage(file); user.EndContainedImpersonate(); if (Icon.EndsWith(".ico")) { context.Response.Redirect(VirtualPathUtility.ToAbsolute("~/api/mycomputer/" + Icon)); } else { context.Response.Redirect(VirtualPathUtility.ToAbsolute("~/images/icons/" + Icon)); } } }
/// <summary> /// Get the thumbnail image. /// </summary> /// <param name="thumbnail"><see cref="ShellThumbnail" />.</param> /// <param name="updateImageSource">Update action.</param> /// <returns></returns> public static async Task GetThumbnailAsync(ShellThumbnail thumbnail, Action <ImageSource> updateImageSource) { Contract.Requires <ArgumentNullException>(thumbnail != null); var dg = new DrawingGroup(); // Get thumbnail image. var thumbnailBitmapSource = await GetThumbnailBitmapSourceAsync(thumbnail); // Add thumbnail frame. var thumbnailFrame = new RectangleGeometry(new Rect(0, 0, thumbnailBitmapSource.Width + 2, thumbnailBitmapSource.Height + 2)); dg.Children.Add(new GeometryDrawing(Brushes.Transparent, null, thumbnailFrame)); // Add thumbnail rectangle. var thumbnailRect = new Rect(1, 1, thumbnailBitmapSource.PixelWidth, thumbnailBitmapSource.PixelHeight); dg.Children.Add(new ImageDrawing(thumbnailBitmapSource, thumbnailRect)); if (thumbnail.OverlayIndex > 0) { // Get overlay icon image. var overlayBitmapSource = await GetOverlayIconBitmapSourceAsync(thumbnail); var overlayIconRect = new Rect(0, 0, overlayBitmapSource.PixelWidth, overlayBitmapSource.PixelHeight); var rect = overlayIconRect; if (thumbnail.OriginalWidth < 256) { overlayIconRect.Offset(-2.0, thumbnailRect.Height - overlayIconRect.Height + 2.0); rect.Offset(0, thumbnailRect.Height - overlayIconRect.Height); } else { var scale = (thumbnail.OriginalWidth * 0.38) / overlayIconRect.Width; overlayIconRect.Scale(scale, scale); overlayIconRect.Offset(-4.0, thumbnailRect.Height - overlayIconRect.Height + 4.0); rect.Scale(scale, scale); rect.Offset(0, thumbnailRect.Height - rect.Height); } dg.Children.Add(new ImageDrawing(overlayBitmapSource, overlayIconRect)); // Create overlay image. var dgOverlay = new DrawingGroup(); dgOverlay.Children.Add(new GeometryDrawing(Brushes.Transparent, null, new RectangleGeometry(thumbnailRect))); dgOverlay.Children.Add(new ImageDrawing(overlayBitmapSource, rect)); if (dgOverlay.CanFreeze) { dgOverlay.Freeze(); } } if (dg.CanFreeze) { dg.Freeze(); } updateImageSource.Invoke(new DrawingImage(dg)); }
/// <summary> /// Initialize a new instance of the <see cref="ShellImageSource" /> class, /// to the specified <see cref="ShellThumbnail" />. /// </summary> /// <param name="shellThumbnail"><see cref="ShellThumbnail" />.</param> public ShellImageSource(ShellThumbnail shellThumbnail) { Contract.Requires <ArgumentNullException>(shellThumbnail != null); this.ShellThumbnail = shellThumbnail; }