public void GetThumbnail() { try { int THUMB_SIZE = 500; var thumbnail = WindowsThumbnailProvider.GetThumbnail(Library.Tools.IO.MyDirectory.GetSolutionDirectory() + PARTPATH, THUMB_SIZE, THUMB_SIZE, ThumbnailOptions.None); if (thumbnail == null) { throw new Exception(); } var thumbnail2 = WindowsThumbnailProvider.GetThumbnail(Library.Tools.IO.MyDirectory.GetSolutionDirectory() + ASMPPATH, THUMB_SIZE, THUMB_SIZE, ThumbnailOptions.None); if (thumbnail2 == null) { throw new Exception(); } //var tempFile = Library.Tools.IO.MyFile.GenerateTempFilePath("bmp"); //thumbnail.Save(tempFile); //System.Diagnostics.Process.Start(tempFile); //var PDMTEst = @"C:\_LECAPITAINE_DEV\T1-Test\SheetMetalPart.SLDPRT"; //var thumbnail3 = WindowsThumbnailProvider.GetThumbnail(PDMTEst, THUMB_SIZE, THUMB_SIZE, ThumbnailOptions.None); //if (thumbnail3 == null) // throw new Exception(); } catch (Exception ex) { throw ex; } }
//public ImageData imageData { get; } public Image GetImage(ImageData imageData) { foreach (Lazy <iLoader, iLoaderData> i in operations) { if (i.Metadata.FileTypes.Contains(imageData.FileExt)) { return(i.Value.Load(imageData)); } } string iconName = Path.Combine(System.IO.Path.GetTempPath(), "ESUFileExplorer", imageData.FileExt + ".bmp"); Image icon; if (!File.Exists(iconName)) { string fName; bool isFile = true; FileStream fileStream = null; DirectoryInfo directoryStream = null; if (imageData.FileExt != "directory") { fName = Path.Combine(System.IO.Path.GetTempPath(), "ESUFileExplorer", Guid.NewGuid().ToString() + imageData.FileExt); fileStream = File.Create(fName); } else { isFile = false; fName = Path.Combine(System.IO.Path.GetTempPath(), "ESUFileExplorer", Guid.NewGuid().ToString()); directoryStream = Directory.CreateDirectory(fName); } int THUMB_SIZE = 256; Bitmap thumbnail = WindowsThumbnailProvider.GetThumbnail( fName, THUMB_SIZE, THUMB_SIZE, ThumbnailOptions.IconOnly); thumbnail.Save(iconName); if (isFile) { fileStream.Close(); File.Delete(fName); } else { directoryStream.Delete(); } } icon = Bitmap.FromFile(iconName); return(icon); //return Properties.Resources.empty; }
protected override void OnPreviewDragEnter(DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) { var fileName = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString(); var fileBrush = WindowsThumbnailProvider.GetThumbnailBrush(fileName); _adorner = new DragAdorner(this, new Size(256, 256), fileBrush); } base.OnPreviewDragEnter(e); }
void DoWork(object parameter) { // emulate image loading Cell cell = (Cell)parameter; //Thread.Sleep(1000); //Image img = Image.FromFile(cell.FileName); //ShellFile shellFile = ShellFile.FromFilePath(cell.FileName); //Bitmap shellThumb = shellFile.Thumbnail.ExtraLargeBitmap; //Bitmap shellThumb = shellFile.Thumbnail.LargeBitmap; //string x= shellFile.Properties.System.Image.Dimensions.Value; // Image.FromFile(cell.FileName); //Stream resultStream = new ThumbnailCreator().CreateThumbnailStream(thumbnailSize: 256, imageStream: new FileStream(cell.FileName, FileMode.Open, FileAccess.Read), imageFormat: Format.Jpeg); Image img = Image.FromFile(cell.FileName);//ThumbnailExtractor.FromFile(cell.FileName, new Size(256, 256),UseEmbeddedThumbnails.Auto,true,true); Size thumbnailSize = WindowsThumbnailProvider.GetThumbnailSize(img); if (!string.IsNullOrEmpty(cell.RectBody)) { using (Graphics g = Graphics.FromImage(img)) { Color customColor = Color.FromArgb(100, Color.Red); SolidBrush shadowBrush = new SolidBrush(customColor); Pen pen = new Pen(Color.Red, 8); Rectangle rectFToFill = new Rectangle(); string[] vehicleLocation = cell.RectBody.Split(','); if (vehicleLocation.Length == 4) { rectFToFill.X = Convert.ToInt32(vehicleLocation[0]); rectFToFill.Y = Convert.ToInt32(vehicleLocation[1]); rectFToFill.Width = Convert.ToInt32(vehicleLocation[2]); rectFToFill.Height = Convert.ToInt32(vehicleLocation[3]); } //rectFToFill.Inflate(new Size(50, 50)); //g.FillRectangles(shadowBrush, new RectangleF[] { rectFToFill }); g.DrawRectangles(pen, new Rectangle[] { rectFToFill }); } } Image thumbnail = img.GetThumbnailImage(thumbnailSize.Width, thumbnailSize.Height, null, IntPtr.Zero); gridControl1.Invoke(new MethodInvoker(() => { layoutView1.SetRowCellValue(layoutView1.GetRowHandle(cell.RowIndex), cell.FieldName, thumbnail); })); //img.Dispose(); }
public IntPtr GetHBitmap(int iconSize, bool isThumbnail, bool isForce = false) { ThumbnailOptions options = ThumbnailOptions.None; if (isThumbnail) { options = ThumbnailOptions.ThumbnailOnly; if (!isForce) { options |= ThumbnailOptions.InCacheOnly; } } else { options |= ThumbnailOptions.IconOnly; } return(WindowsThumbnailProvider.GetThumbnail(this.PIDL, iconSize, iconSize, options)); }
void DoWork(object parameter) { // emulate image loading Cell cell = (Cell)parameter; //Thread.Sleep(1000); //Image img = Image.FromFile(cell.FileName); //ShellFile shellFile = ShellFile.FromFilePath(cell.FileName); //Bitmap shellThumb = shellFile.Thumbnail.ExtraLargeBitmap; //Bitmap shellThumb = shellFile.Thumbnail.LargeBitmap; Image img = Image.FromFile(cell.FileName); Size thumbnailSize = WindowsThumbnailProvider.GetThumbnailSize(img); if (!string.IsNullOrEmpty(cell.RectBody)) { using (Graphics g = Graphics.FromImage(img)) { Color customColor = Color.FromArgb(100, Color.Red); SolidBrush shadowBrush = new SolidBrush(customColor); Pen pen = new Pen(Color.Red, 8); Rectangle rectFToFill = new Rectangle(); string[] vehicleLocation = cell.RectBody.Split(','); if (vehicleLocation.Length == 4) { rectFToFill.X = Convert.ToInt32(vehicleLocation[0]); rectFToFill.Y = Convert.ToInt32(vehicleLocation[1]); rectFToFill.Width = Convert.ToInt32(vehicleLocation[2]); rectFToFill.Height = Convert.ToInt32(vehicleLocation[3]); } //rectFToFill.Inflate(new Size(50, 50)); //g.FillRectangles(shadowBrush, new RectangleF[] { rectFToFill }); g.DrawRectangles(pen, new Rectangle[] { rectFToFill }); } } Image thumbnail = img.GetThumbnailImage(thumbnailSize.Width, thumbnailSize.Height, null, IntPtr.Zero); gridControl1.Invoke(new MethodInvoker(() => { layoutView1.SetRowCellValue(layoutView1.GetRowHandle(cell.RowIndex), cell.FieldName, thumbnail); })); }
public static MediaFile LoadFromFile(FileInfo file) { int THUMB_SIZE = 256; Bitmap thumbnail = WindowsThumbnailProvider.GetThumbnail( file.FullName, THUMB_SIZE, THUMB_SIZE, ThumbnailOptions.None); MemoryStream stream = new MemoryStream(); thumbnail.Save(stream, thumbnail.RawFormat); var texture = new Texture2D(thumbnail.Width, thumbnail.Height); texture.LoadImage(stream.ToArray()); var sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.one * 0.5f, 100, 1); return(new MediaFile { Path = file.FullName, FileName = file.Name, CoverImage = sprite }); }
internal static BitmapSource GetThumbnail(string value) { lock (_thumbLock) { if (_thumbnails.ContainsKey(value)) { if (_thumbnails[value].Item1 != null) { return(_thumbnails[value].Item1); } else { var width = _thumbnails[value].Item2; var thumbnail = Convert(WindowsThumbnailProvider.GetThumbnail((string)value, width, 100, ThumbnailOptions.None)); _thumbnails[value] = new Tuple <BitmapSource, int>(thumbnail, width); return(_thumbnails[value].Item1); } } } return(null); }
public static Bitmap GetThumbnail(this FileInfo file, Size size, ThumbnailOptions options = ThumbnailOptions.ThumbnailOnly) { return(WindowsThumbnailProvider.GetThumbnail(file.FullName, size.Width, size.Height, options)); }
private static ImageSource LoadImage(string path) { ImageSource image = null; ImageType type = ImageType.Error; try { if (string.IsNullOrEmpty(path)) { // return new ImageResult(ImageCache[Constant.ErrorIcon], ImageType.Error); } if (ImageCache.ContainsKey(path)) { return(ImageCache[path]); } if (path?.StartsWith("data:", StringComparison.OrdinalIgnoreCase) ?? false) { var imageSource = new BitmapImage(new Uri(path)); imageSource.Freeze(); return(imageSource); } if (!Path.IsPathRooted(path)) { path = Path.Combine(Constant.ProgramDirectory, "Images", Path.GetFileName(path)); } if (Directory.Exists(path)) { /* Directories can also have thumbnails instead of shell icons. * Generating thumbnails for a bunch of folders while scrolling through * results from Everything makes a big impact on performance and * Wox responsibility. * - Solution: just load the icon */ type = ImageType.Folder; image = WindowsThumbnailProvider.GetThumbnail(path, Constant.ThumbnailSize, Constant.ThumbnailSize, ThumbnailOptions.IconOnly); } else if (File.Exists(path)) { var extension = Path.GetExtension(path).ToLower(); if (ImageExtensions.Contains(extension)) { type = ImageType.ImageFile; /* Although the documentation for GetImage on MSDN indicates that * if a thumbnail is available it will return one, this has proved to not * be the case in many situations while testing. * - Solution: explicitly pass the ThumbnailOnly flag */ image = WindowsThumbnailProvider.GetThumbnail(path, Constant.ThumbnailSize, Constant.ThumbnailSize, ThumbnailOptions.ThumbnailOnly); } else { type = ImageType.File; image = WindowsThumbnailProvider.GetThumbnail(path, Constant.ThumbnailSize, Constant.ThumbnailSize, ThumbnailOptions.None); } } //else //{ // image = ImageCache[Constant.ErrorIcon]; // path = Constant.ErrorIcon; //} if (type != ImageType.Error) { image.Freeze(); } } catch (System.Exception e) { Trace.WriteLine($"|ImageLoader.Load|Failed to get thumbnail for {path} - {e}"); type = ImageType.Error; //image = ImageCache[Constant.ErrorIcon]; //ImageCache[path] = image; } return(image); }
private void button1_Click(object sender, EventArgs e) { var files = Directory.GetFiles(textBox1.Text); var folders = Directory.GetDirectories(textBox1.Text); files = folders.Concat(files).ToArray(); var sizeX = Int32.Parse(comboBox2.Text); var sizeY = Int32.Parse(comboBox3.Text); // this demo only allows using one flag at a time, but you get combine them bitwise if needed ThumbnailOptions options = ThumbnailOptions.None; if (comboBox1.Text == "BiggerSizeOk") { options = ThumbnailOptions.BiggerSizeOk; } if (comboBox1.Text == "InMemoryOnly") { options = ThumbnailOptions.InMemoryOnly; } if (comboBox1.Text == "IconOnly") { options = ThumbnailOptions.IconOnly; } if (comboBox1.Text == "ThumbnailOnly") { options = ThumbnailOptions.ThumbnailOnly; } if (comboBox1.Text == "InCacheOnly") { options = ThumbnailOptions.InCacheOnly; } if (comboBox1.Text == "Win8CropToSquare") { options = ThumbnailOptions.Win8CropToSquare; } if (comboBox1.Text == "Win8WideThumbnails") { options = ThumbnailOptions.Win8WideThumbnails; } if (comboBox1.Text == "Win8IconBackground") { options = ThumbnailOptions.Win8IconBackground; } if (comboBox1.Text == "Win8ScaleUp") { options = ThumbnailOptions.Win8ScaleUp; } listView1.Clear(); imageList1.Images.Clear(); imageList1.ImageSize = new Size(sizeX, sizeY); foreach (var f in files) { Bitmap resultBitmap = WindowsThumbnailProvider.GetThumbnail(f, sizeX, sizeY, options); if (resultBitmap != null) { // The returned bitmap can be smaller than requested size if aspect ration does not match exatcly. // If so imageList will scale to specified icon size, which is unwanted. // To get around this I create a new bitmap with required size and paste the bitmap there. Bitmap squareBitmap = new Bitmap(sizeX, sizeY); Graphics g = Graphics.FromImage(squareBitmap); g.DrawImage(resultBitmap, new Point(0, 0)); imageList1.Images.Add(f, squareBitmap); listView1.Items.Add(Path.GetFileName(f), f); } } }