private void HandleRenderingQueueProgressMessageReport(string source, string destination, double progress, string status, IBitmapCore image) { Application.Invoke(delegate { source_label.Text = source; destination_label.Text = destination; processing_progressbar.Fraction = progress; processing_progressbar.Text = status; mProcessingStatusIcon.Tooltip = "Processing " + System.IO.Path.GetFileName(source) + ". " + status + " (" + ((int)(progress * 100)).ToString() + "%)"; thumb_image.Visible = (image != null); if ((DateTime.Now - updateMoment).TotalMilliseconds > drawingTimeSpan.TotalMilliseconds * 5 && image != null && this.Visible) { updateMoment = DateTime.Now; // Drawing int size = 300, margins = 30; thumb_image.SetSizeRequest(size + margins, size + margins); using (Gdk.Pixmap pm = new Gdk.Pixmap(thumb_image.GdkWindow, size + margins, size + margins, -1)) { using (Gdk.Pixbuf pb = new Gdk.Pixbuf(Gdk.Colorspace.Rgb, false, 8, image.Width, image.Height)) { using (Gdk.GC gc = new Gdk.GC(thumb_image.GdkWindow)) { ((FloatBitmapGtk)image).DrawToPixbuf(pb, null); Gdk.Pixbuf pb2; if (pb.Width > pb.Height) { pb2 = pb.ScaleSimple(size, (int)((double)pb.Height / pb.Width * size), Gdk.InterpType.Bilinear); } else { pb2 = pb.ScaleSimple((int)((double)pb.Width / pb.Height * size), size, Gdk.InterpType.Bilinear); } pm.DrawRectangle(gc, true, new Gdk.Rectangle(0, 0, size + margins, size + margins)); pm.DrawPixbuf(gc, pb2, 0, 0, (size + margins) / 2 - pb2.Width / 2, (size + margins) / 2 - pb2.Height / 2, pb2.Width, pb2.Height, Gdk.RgbDither.Max, 0, 0); pb2.Dispose(); thumb_image.SetFromPixmap(pm, null); } } } drawingTimeSpan = DateTime.Now - updateMoment; } }); }
protected void UpdatePreview() { thumb_image.Clear(); FileIsGood = false; int size = 200, margins = 30; if (System.IO.File.Exists(mFilename)) // Selected item is a file { origsize_label.Markup = ""; GLib.Timeout.Add(100, new GLib.TimeoutHandler(delegate { Gdk.Pixmap pm = null; Gdk.GC gc = null; Gdk.Pixbuf pb = null; try { pm = new Gdk.Pixmap(thumb_image.GdkWindow, size + margins, size + margins, -1); gc = new Gdk.GC(thumb_image.GdkWindow); pm.DrawRectangle(gc, true, new Gdk.Rectangle(0, 0, size + margins, size + margins)); RawDescriptionLoader rdl = RawDescriptionLoader.FromFile(mFilename); string idtext = ""; try { idtext += "Shot has been taken\n" + " on <b>" + rdl.TimeStamp.ToString("MMMM, d, yyyy") + "</b> at <b>" + rdl.TimeStamp.ToString("h:mm:ss tt") + "</b>,\n"; idtext += " with <b>" + rdl.CameraMaker + " " + rdl.CameraModel + "</b>\n\n"; idtext += "ISO speed: <b>" + rdl.ISOSpeed.ToString("0") + "</b>\n"; if (rdl.Shutter > 1) { idtext += "Shutter: <b>" + rdl.Shutter.ToString("0.0") + "</b> sec\n"; } else { idtext += "Shutter: <b>1/" + (1.0 / (rdl.Shutter + 0.000001)).ToString("0") + "</b> sec\n"; } idtext += "Aperture: <b>" + rdl.Aperture.ToString("0.0") + "</b>\n" + "Focal length: <b>" + rdl.FocalLength.ToString("0") + "</b> mm\n"; if (rdl.Artist != "") { idtext += "Artist: <b>" + rdl.Artist + "</b>\n"; } if (rdl.Description != "") { idtext += "Description: <b>" + rdl.Description + "</b>\n"; } Console.WriteLine(rdl.Flip); // Creating the thumbnail pixbuf pb = new Gdk.Pixbuf(rdl.ThumbnailData); } catch (Exception ex) { Console.WriteLine("Can't load the thumbnail: " + ex.Message); idtext += "\n<i>Can't load the thumbnail.</i>"; } identification_label.Markup = idtext; if (pb != null) { // Scaling the thumbnail Gdk.Pixbuf pbold = pb; int imgw = pb.Width, imgh = pb.Height; if (pb.Width > pb.Height) { pb = pb.ScaleSimple(size, (int)((double)pb.Height / pb.Width * size), Gdk.InterpType.Bilinear); } else { pb = pb.ScaleSimple((int)((double)pb.Width / pb.Height * size), size, Gdk.InterpType.Bilinear); } pbold.Dispose(); // Rotating the thumbnail if (rdl.Flip != RawDescriptionLoader.FlipValues.None) { pbold = pb; if (rdl.Flip == RawDescriptionLoader.FlipValues.UpsideDown) { pb = pb.RotateSimple(Gdk.PixbufRotation.Upsidedown); } else if (rdl.Flip == RawDescriptionLoader.FlipValues.Clockwise) { int t = imgw; imgw = imgh; imgh = t; pb = pb.RotateSimple(Gdk.PixbufRotation.Clockwise); } else if (rdl.Flip == RawDescriptionLoader.FlipValues.Counterclockwise) { int t = imgw; imgw = imgh; imgh = t; pb = pb.RotateSimple(Gdk.PixbufRotation.Counterclockwise); } pbold.Dispose(); } origsize_label.Markup = "Image size: <b>" + imgw + "</b> x <b>" + imgh + "</b>"; pm.DrawPixbuf(gc, pb, 0, 0, (size + margins) / 2 - pb.Width / 2, (size + margins) / 2 - pb.Height / 2, pb.Width, pb.Height, Gdk.RgbDither.Max, 0, 0); thumb_image.SetFromPixmap(pm, null); pb.Dispose(); } FileIsGood = true; } catch (Exception #if DEBUG ex #endif ) { #if DEBUG Console.WriteLine("Exception occured during the thumbnail loading process: " + ex.Message); #endif identification_label.Wrap = true; identification_label.Markup = "<i>Cannot decode the selected file. " + "Maybe it's corrupted or the user hasn't enough access rights to open it.</i>"; FileIsGood = false; } finally { if (gc != null) { gc.Dispose(); } if (pm != null) { pm.Dispose(); } } return(false); })); } }
protected void UpdatePreview() { thumb_image.Clear(); FileIsGood = false; int size = 200, margins = 30; if (System.IO.File.Exists(mFilename)) // Selected item is a file { origsize_label.Markup = ""; GLib.Timeout.Add(100, new GLib.TimeoutHandler(delegate { Gdk.Pixmap pm = null; Gdk.GC gc = null; Gdk.Pixbuf pb = null; try { pm = new Gdk.Pixmap(thumb_image.GdkWindow, size + margins, size + margins, -1); gc = new Gdk.GC(thumb_image.GdkWindow); pm.DrawRectangle(gc, true, new Gdk.Rectangle(0, 0, size + margins, size + margins)); RawDescriptionLoader rdl = RawDescriptionLoader.FromFile(mFilename); string idtext = ""; try { idtext += "Shot has been taken\n" + " on <b>" + rdl.TimeStamp.ToString("MMMM, d, yyyy") + "</b> at <b>" + rdl.TimeStamp.ToString("h:mm:ss tt") + "</b>,\n"; idtext += " with <b>" + rdl.CameraMaker + " " + rdl.CameraModel + "</b>\n\n"; idtext += "ISO speed: <b>" + rdl.ISOSpeed.ToString("0") + "</b>\n"; if (rdl.Shutter > 1) idtext += "Shutter: <b>" + rdl.Shutter.ToString("0.0") + "</b> sec\n"; else idtext += "Shutter: <b>1/" + (1.0 / (rdl.Shutter + 0.000001)).ToString("0") + "</b> sec\n"; idtext += "Aperture: <b>" + rdl.Aperture.ToString("0.0") + "</b>\n" + "Focal length: <b>" + rdl.FocalLength.ToString("0") + "</b> mm\n"; if (rdl.Artist != "") idtext += "Artist: <b>" + rdl.Artist + "</b>\n"; if (rdl.Description != "") idtext += "Description: <b>" + rdl.Description + "</b>\n"; Console.WriteLine(rdl.Flip); // Creating the thumbnail pixbuf pb = new Gdk.Pixbuf(rdl.ThumbnailData); } catch (Exception ex) { Console.WriteLine("Can't load the thumbnail: " + ex.Message); idtext += "\n<i>Can't load the thumbnail.</i>"; } identification_label.Markup = idtext; if (pb != null) { // Scaling the thumbnail Gdk.Pixbuf pbold = pb; int imgw = pb.Width, imgh = pb.Height; if (pb.Width > pb.Height) pb = pb.ScaleSimple(size, (int)((double)pb.Height / pb.Width * size), Gdk.InterpType.Bilinear); else pb = pb.ScaleSimple((int)((double)pb.Width / pb.Height * size), size, Gdk.InterpType.Bilinear); pbold.Dispose(); // Rotating the thumbnail if (rdl.Flip != RawDescriptionLoader.FlipValues.None) { pbold = pb; if (rdl.Flip == RawDescriptionLoader.FlipValues.UpsideDown) pb = pb.RotateSimple(Gdk.PixbufRotation.Upsidedown); else if (rdl.Flip == RawDescriptionLoader.FlipValues.Clockwise) { int t = imgw; imgw = imgh; imgh = t; pb = pb.RotateSimple(Gdk.PixbufRotation.Clockwise); } else if (rdl.Flip == RawDescriptionLoader.FlipValues.Counterclockwise) { int t = imgw; imgw = imgh; imgh = t; pb = pb.RotateSimple(Gdk.PixbufRotation.Counterclockwise); } pbold.Dispose(); } origsize_label.Markup = "Image size: <b>" + imgw + "</b> x <b>" + imgh + "</b>"; pm.DrawPixbuf(gc, pb, 0, 0, (size + margins) / 2 - pb.Width / 2, (size + margins) / 2 - pb.Height / 2, pb.Width, pb.Height, Gdk.RgbDither.Max, 0, 0); thumb_image.SetFromPixmap(pm, null); pb.Dispose(); } FileIsGood = true; } catch (Exception #if DEBUG ex #endif ) { #if DEBUG Console.WriteLine("Exception occured during the thumbnail loading process: " + ex.Message); #endif identification_label.Wrap = true; identification_label.Markup = "<i>Cannot decode the selected file. "+ "Maybe it's corrupted or the user hasn't enough access rights to open it.</i>"; FileIsGood = false; } finally { if (gc != null) gc.Dispose(); if (pm != null) pm.Dispose(); } return false; })); } }
private void HandleRenderingQueueProgressMessageReport(string source, string destination, double progress, string status, IBitmapCore image) { Application.Invoke(delegate { source_label.Text = source; destination_label.Text = destination; processing_progressbar.Fraction = progress; processing_progressbar.Text = status; mProcessingStatusIcon.Tooltip = "Processing " + System.IO.Path.GetFileName(source) + ". " + status + " (" + ((int)(progress * 100)).ToString() + "%)"; thumb_image.Visible = (image != null); if ((DateTime.Now - updateMoment).TotalMilliseconds > drawingTimeSpan.TotalMilliseconds * 5 && image != null && this.Visible) { updateMoment = DateTime.Now; // Drawing int size = 300, margins = 30; thumb_image.SetSizeRequest(size + margins, size + margins); using (Gdk.Pixmap pm = new Gdk.Pixmap(thumb_image.GdkWindow, size + margins, size + margins, -1)) { using (Gdk.Pixbuf pb = new Gdk.Pixbuf(Gdk.Colorspace.Rgb, false, 8, image.Width, image.Height)) { using (Gdk.GC gc = new Gdk.GC(thumb_image.GdkWindow)) { ((FloatBitmapGtk)image).DrawToPixbuf(pb, null); Gdk.Pixbuf pb2; if (pb.Width > pb.Height) pb2 = pb.ScaleSimple(size, (int)((double)pb.Height / pb.Width * size), Gdk.InterpType.Bilinear); else pb2 = pb.ScaleSimple((int)((double)pb.Width / pb.Height * size), size, Gdk.InterpType.Bilinear); pm.DrawRectangle(gc, true, new Gdk.Rectangle(0, 0, size + margins, size + margins)); pm.DrawPixbuf(gc, pb2, 0, 0, (size + margins) / 2 - pb2.Width / 2, (size + margins) / 2 - pb2.Height / 2, pb2.Width, pb2.Height, Gdk.RgbDither.Max, 0, 0); pb2.Dispose(); thumb_image.SetFromPixmap(pm, null); } } } drawingTimeSpan = DateTime.Now - updateMoment; } }); }