public void Import(string fileName) { Pixbuf bg; // Handle any EXIF orientation flags using (var fs = new FileStream (fileName, FileMode.Open, FileAccess.Read)) bg = new Pixbuf (fs); bg = bg.ApplyEmbeddedOrientation (); Size imagesize = new Size (bg.Width, bg.Height); Document doc = PintaCore.Workspace.CreateAndActivateDocument (fileName, imagesize); doc.HasFile = true; doc.ImageSize = imagesize; doc.Workspace.CanvasSize = imagesize; Layer layer = doc.AddNewLayer (Path.GetFileName (fileName)); using (Cairo.Context g = new Cairo.Context (layer.Surface)) { CairoHelper.SetSourcePixbuf (g, bg, 0, 0); g.Paint (); } bg.Dispose (); }
public ImageCanvas(string fileName, List <BarierPoint> shapeListPoint) { this.fileName = fileName; if (shapeListPoint != null) { this.shapeListPoint = shapeListPoint; } else { shapeListPoint = new List <BarierPoint>(); } if (MainClass.Settings.ImageEditors == null) { MainClass.Settings.ImageEditors = new Option.Settings.ImageEditorSetting(); MainClass.Settings.ImageEditors.LineWidth = 3; MainClass.Settings.ImageEditors.PointWidth = 5; MainClass.Settings.ImageEditors.LineColor = new Option.Settings.BackgroundColors(10, 10, 255, 32767); MainClass.Settings.ImageEditors.PointColor = new Option.Settings.BackgroundColors(10, 10, 255, 32767); MainClass.Settings.ImageEditors.SelectPointColor = new Option.Settings.BackgroundColors(255, 10, 10, 32767); } lineWitdth = MainClass.Settings.ImageEditors.LineWidth; pointWidth = MainClass.Settings.ImageEditors.PointWidth; Gdk.Color gdkLineColor = new Gdk.Color(MainClass.Settings.ImageEditors.LineColor.Red, MainClass.Settings.ImageEditors.LineColor.Green, MainClass.Settings.ImageEditors.LineColor.Blue); Gdk.Color gdkPointColor = new Gdk.Color(MainClass.Settings.ImageEditors.PointColor.Red, MainClass.Settings.ImageEditors.PointColor.Green, MainClass.Settings.ImageEditors.PointColor.Blue); Gdk.Color gdkSelPointColor = new Gdk.Color(MainClass.Settings.ImageEditors.SelectPointColor.Red, MainClass.Settings.ImageEditors.SelectPointColor.Green, MainClass.Settings.ImageEditors.SelectPointColor.Blue); colorLine = gdkLineColor.ToCairoColor(MainClass.Settings.ImageEditors.LineColor.Alpha); colorPoint = gdkPointColor.ToCairoColor(MainClass.Settings.ImageEditors.PointColor.Alpha); colorSelectPoint = gdkSelPointColor.ToCairoColor(MainClass.Settings.ImageEditors.SelectPointColor.Alpha); Gdk.Pixbuf bg; try{ using (var fs = new System.IO.FileStream(fileName, System.IO.FileMode.Open)) bg = new Gdk.Pixbuf(fs); bg = bg.ApplyEmbeddedOrientation(); this.HeightImage = bg.Height; this.WidthImage = bg.Width; }catch (Exception ex) { Tool.Logger.Error(ex.Message, null); } }
public ImageCanvas(string fileName, List<BarierPoint> shapeListPoint) { this.fileName = fileName; if (shapeListPoint != null) this.shapeListPoint = shapeListPoint; else shapeListPoint = new List<BarierPoint>(); if(MainClass.Settings.ImageEditors == null){ MainClass.Settings.ImageEditors = new Option.Settings.ImageEditorSetting(); MainClass.Settings.ImageEditors.LineWidth = 3; MainClass.Settings.ImageEditors.PointWidth = 5; MainClass.Settings.ImageEditors.LineColor = new Option.Settings.BackgroundColors(10,10,255,32767); MainClass.Settings.ImageEditors.PointColor = new Option.Settings.BackgroundColors(10,10,255,32767); MainClass.Settings.ImageEditors.SelectPointColor = new Option.Settings.BackgroundColors(255,10,10,32767); } lineWitdth = MainClass.Settings.ImageEditors.LineWidth; pointWidth = MainClass.Settings.ImageEditors.PointWidth; Gdk.Color gdkLineColor = new Gdk.Color(MainClass.Settings.ImageEditors.LineColor.Red, MainClass.Settings.ImageEditors.LineColor.Green,MainClass.Settings.ImageEditors.LineColor.Blue); Gdk.Color gdkPointColor = new Gdk.Color(MainClass.Settings.ImageEditors.PointColor.Red, MainClass.Settings.ImageEditors.PointColor.Green,MainClass.Settings.ImageEditors.PointColor.Blue); Gdk.Color gdkSelPointColor = new Gdk.Color(MainClass.Settings.ImageEditors.SelectPointColor.Red, MainClass.Settings.ImageEditors.SelectPointColor.Green,MainClass.Settings.ImageEditors.SelectPointColor.Blue); colorLine = gdkLineColor.ToCairoColor(MainClass.Settings.ImageEditors.LineColor.Alpha); colorPoint = gdkPointColor.ToCairoColor(MainClass.Settings.ImageEditors.PointColor.Alpha); colorSelectPoint = gdkSelPointColor.ToCairoColor(MainClass.Settings.ImageEditors.SelectPointColor.Alpha); Gdk.Pixbuf bg; try{ using (var fs = new System.IO.FileStream(fileName, System.IO.FileMode.Open)) bg = new Gdk.Pixbuf(fs); bg = bg.ApplyEmbeddedOrientation(); this.HeightImage = bg.Height; this.WidthImage= bg.Width; }catch(Exception ex){ Tool.Logger.Error(ex.Message,null); } }
protected override bool OnExposeEvent(Gdk.EventExpose e) { Gdk.Pixbuf bg; try{ //if(fileName.ToLower().EndsWith (".svg")){ //bg = Rsvg.Pixbuf.FromFile(fileName); // bg = Rsvg.Tool.PixbufFromFileAtSize(fileName,800,600); //} else{ using (var fs = new System.IO.FileStream(fileName, System.IO.FileMode.Open)) bg = new Gdk.Pixbuf(fs); //} }catch (Exception ex) { Tool.Logger.Error(ex.Message, null); return(true); } bg = bg.ApplyEmbeddedOrientation(); this.HeightImage = bg.Height; this.WidthImage = bg.Width; if (this.listPoint == null) { this.listPoint = new List <BarierPoint>(); if (this.shapeListPoint != null) { foreach (BarierPoint bp in this.shapeListPoint) { BarierPoint updateBp = new BarierPoint(); updateBp.X = bp.X + (1 / HeightImage); updateBp.Y = -bp.Y + (1 / WidthImage); listPoint.Add(updateBp); } } } //Size imagesize = new Size (bg.Width, bg.Height); width = (int)(bg.Width * scaling); height = (int)(bg.Height * scaling); int x, y, w, h, d = 0; this.ParentWindow.GetGeometry(out x, out y, out w, out h, out d); drawOffsetX = (w - width) / 2; if (drawOffsetX < 0) { drawOffsetX = 0; } drawOffsetY = (h - height) / 2; if (drawOffsetY < 0) { drawOffsetY = 0; } using (Context cr = Gdk.CairoHelper.Create(e.Window)) { if (!MainClass.Platform.IsMac) { FillChecks(cr, 0, 0, w, h); //w, h); cr.Save(); cr.DrawRectangle(new Cairo.Rectangle(drawOffsetX - 1, drawOffsetY - 1, width + 1, height + 1), new Cairo.Color(0, 0, 0), 1); cr.Rectangle(new Cairo.Rectangle(drawOffsetX - 1, drawOffsetY - 1, width, height)); cr.Clip(); } cr.Scale(scaling, scaling); CairoHelper.SetSourcePixbuf(cr, bg, drawOffsetX / scaling, drawOffsetY / scaling); cr.Paint(); this.WidthRequest = width + 1; this.HeightRequest = height + 1; if (showBarierLayer) { Draw(cr, width, height); } cr.Scale(scaling, scaling); } return(true); /*using (Context cr = Gdk.CairoHelper.Create (e.Window)) { * int w, h; * e.Window.GetSize (out w, out h); * Draw (cr, w, h); * } * return true;*/ }
protected override bool OnExposeEvent(Gdk.EventExpose e) { Gdk.Pixbuf bg; try{ //if(fileName.ToLower().EndsWith (".svg")){ //bg = Rsvg.Pixbuf.FromFile(fileName); // bg = Rsvg.Tool.PixbufFromFileAtSize(fileName,800,600); //} else{ using (var fs = new System.IO.FileStream(fileName, System.IO.FileMode.Open)) bg = new Gdk.Pixbuf(fs); //} }catch(Exception ex){ Tool.Logger.Error(ex.Message,null); return true; } bg = bg.ApplyEmbeddedOrientation(); this.HeightImage = bg.Height; this.WidthImage= bg.Width; if ( this.listPoint == null ){ this.listPoint = new List<BarierPoint>(); if( this.shapeListPoint != null ){ foreach(BarierPoint bp in this.shapeListPoint){ BarierPoint updateBp = new BarierPoint(); updateBp.X = bp.X +(1/HeightImage); updateBp.Y = -bp.Y +(1/WidthImage); listPoint.Add(updateBp); } } } //Size imagesize = new Size (bg.Width, bg.Height); width = (int)(bg.Width * scaling); height = (int)(bg.Height * scaling); int x, y, w, h, d = 0; this.ParentWindow.GetGeometry(out x, out y, out w, out h, out d); drawOffsetX = (w - width) / 2; if (drawOffsetX < 0) drawOffsetX = 0; drawOffsetY = (h - height) / 2; if (drawOffsetY < 0) drawOffsetY = 0; using (Context cr = Gdk.CairoHelper.Create(e.Window)) { if(!MainClass.Platform.IsMac){ FillChecks (cr, 0, 0,w,h);//w, h); cr.Save (); cr.DrawRectangle(new Cairo.Rectangle(drawOffsetX - 1, drawOffsetY - 1, width + 1, height + 1), new Cairo.Color(0, 0, 0), 1); cr.Rectangle(new Cairo.Rectangle(drawOffsetX - 1, drawOffsetY - 1, width, height)); cr.Clip(); } cr.Scale(scaling, scaling); CairoHelper.SetSourcePixbuf(cr, bg, drawOffsetX / scaling, drawOffsetY / scaling); cr.Paint(); this.WidthRequest = width + 1; this.HeightRequest = height + 1; if (showBarierLayer) { Draw(cr, width, height); } cr.Scale(scaling, scaling); } return true; /*using (Context cr = Gdk.CairoHelper.Create (e.Window)) { int w, h; e.Window.GetSize (out w, out h); Draw (cr, w, h); } return true;*/ }