private void HandleApply(object sender, EventArgs args) { BrowsablePointer item = view.Item; EditTarget target = new EditTarget(item); try { using (ImageFile img = ImageFile.Create(item.Current.DefaultVersionUri)) { Cairo.Format format = view.CompletePixbuf().HasAlpha ? Cairo.Format.Argb32 : Cairo.Format.Rgb24; MemorySurface dest = new MemorySurface(format, info.Bounds.Width, info.Bounds.Height); Context ctx = new Context(dest); effect.OnExpose(ctx, info.Bounds); ((IDisposable)ctx).Dispose(); string tmp = ImageFile.TempPath(item.Current.DefaultVersionUri.LocalPath); using (Gdk.Pixbuf output = Widgets.CairoUtils.CreatePixbuf(dest)) { using (System.IO.Stream stream = System.IO.File.OpenWrite(tmp)) { img.Save(output, stream); } } dest.Destroy(); // FIXME Not this again. I need to imlplement a real version of the transfer // function that shows progress in the main window and allows for all the // goodies we'll need. Gnome.Vfs.Result result = Gnome.Vfs.Result.Ok; result = Gnome.Vfs.Xfer.XferUri(new Gnome.Vfs.Uri(UriList.PathToFileUri(tmp).ToString()), new Gnome.Vfs.Uri(target.Uri.ToString()), Gnome.Vfs.XferOptions.Default, Gnome.Vfs.XferErrorMode.Abort, Gnome.Vfs.XferOverwriteMode.Replace, delegate { System.Console.Write("."); return(1); }); target.Commit(); } } catch (System.Exception e) { System.Console.WriteLine(e); target.Delete(); Dialog d = new EditExceptionDialog((Gtk.Window)view.Toplevel, e, view.Item.Current); d.Show(); d.Run(); d.Destroy(); } Destroy(); }
private ImageInfo CreateBlur(ImageInfo source) { double scale = Math.Max(256 / (double)source.Bounds.Width, 256 / (double)source.Bounds.Height); Gdk.Rectangle small = new Gdk.Rectangle(0, 0, (int)Math.Ceiling(source.Bounds.Width * scale), (int)Math.Ceiling(source.Bounds.Height * scale)); MemorySurface image = new MemorySurface(Format.Argb32, small.Width, small.Height); Context ctx = new Context(image); //Pattern solid = new SolidPattern (0, 0, 0, 0); //ctx.Source = solid; //ctx.Paint (); //solid.Destroy (); ctx.Matrix = source.Fit(small); ctx.Operator = Operator.Source; Pattern p = new SurfacePattern(source.Surface); ctx.Source = p; Console.WriteLine(small); ctx.Paint(); p.Destroy(); ((IDisposable)ctx).Dispose(); Gdk.Pixbuf normal = CairoUtils.CreatePixbuf(image); Gdk.Pixbuf blur = PixbufUtils.Blur(normal, 3); ImageInfo overlay = new ImageInfo(blur); blur.Dispose(); normal.Dispose(); image.Destroy(); return(overlay); }
private ImageInfo CreateBlur(ImageInfo source) { double scale = Math.Max (256 / (double) source.Bounds.Width, 256 / (double) source.Bounds.Height); Gdk.Rectangle small = new Gdk.Rectangle (0, 0, (int) Math.Ceiling (source.Bounds.Width * scale), (int) Math.Ceiling (source.Bounds.Height * scale)); MemorySurface image = new MemorySurface (Format.Argb32, small.Width, small.Height); Context ctx = new Context (image); //Pattern solid = new SolidPattern (0, 0, 0, 0); //ctx.Source = solid; //ctx.Paint (); //solid.Destroy (); ctx.Matrix = source.Fit (small); ctx.Operator = Operator.Source; Pattern p = new SurfacePattern (source.Surface); ctx.Source = p; Console.WriteLine (small); ctx.Paint (); p.Destroy (); ((IDisposable)ctx).Dispose (); Gdk.Pixbuf normal = CairoUtils.CreatePixbuf (image); Gdk.Pixbuf blur = PixbufUtils.Blur (normal, 3); ImageInfo overlay = new ImageInfo (blur); blur.Dispose (); normal.Dispose (); image.Destroy (); return overlay; }
private void HandleApply (object sender, EventArgs args) { BrowsablePointer item = view.Item; EditTarget target = new EditTarget (item); try { using (ImageFile img = ImageFile.Create (item.Current.DefaultVersionUri)) { Cairo.Format format = view.CompletePixbuf ().HasAlpha ? Cairo.Format.Argb32 : Cairo.Format.Rgb24; MemorySurface dest = new MemorySurface (format, info.Bounds.Width, info.Bounds.Height); Context ctx = new Context (dest); effect.OnExpose (ctx, info.Bounds); ((IDisposable)ctx).Dispose (); string tmp = ImageFile.TempPath (item.Current.DefaultVersionUri.LocalPath); using (Gdk.Pixbuf output = Widgets.CairoUtils.CreatePixbuf (dest)) { using (System.IO.Stream stream = System.IO.File.OpenWrite (tmp)) { img.Save (output, stream); } } dest.Destroy (); // FIXME Not this again. I need to imlplement a real version of the transfer // function that shows progress in the main window and allows for all the // goodies we'll need. Gnome.Vfs.Result result = Gnome.Vfs.Result.Ok; result = Gnome.Vfs.Xfer.XferUri (new Gnome.Vfs.Uri (UriList.PathToFileUri (tmp).ToString ()), new Gnome.Vfs.Uri (target.Uri.ToString ()), Gnome.Vfs.XferOptions.Default, Gnome.Vfs.XferErrorMode.Abort, Gnome.Vfs.XferOverwriteMode.Replace, delegate { System.Console.Write ("."); return 1; }); target.Commit (); } } catch (System.Exception e) { System.Console.WriteLine (e); target.Delete (); Dialog d = new EditExceptionDialog ((Gtk.Window) view.Toplevel, e, view.Item.Current); d.Show (); d.Run (); d.Destroy (); } Destroy (); }