private void Save(Project project) { //Save the image to the project var path = Path.Combine(SavePath, Guid.NewGuid().ToString() + ".png"); var thumbPath = Path.Combine(SavePath, Guid.NewGuid().ToString() + ".png"); NSError error; _img.AsPNG().Save(path, true, out error); if (error != null && error.Code != 0) { //Unable to save image var alert = new UIAlertView { Title = "Error", Message = "Unable to save image. Error code: " + error.Code }; alert.CancelButtonIndex = alert.AddButton("Ok"); alert.Show(); return; } var size = AppreciateUI.Utils.Util.ThumbnailSize; UIGraphics.BeginImageContextWithOptions(size, false, 0f); var context = UIGraphics.GetCurrentContext(); context.TranslateCTM(0, size.Height); context.ScaleCTM(1f, -1f); context.DrawImage(new System.Drawing.RectangleF(0, 0, size.Width, size.Height), _img.CGImage); var cgImage = UIGraphics.GetImageFromCurrentImageContext(); cgImage.AsPNG().Save(thumbPath, true, out error); if (error != null && error.Code != 0) { //Delete the first save.. try { File.Delete(path); } catch (Exception e) { AppreciateUI.Utils.Util.LogException("Unable to delete image file at: " + path, e); } var alert = new UIAlertView { Title = "Error", Message = "Unable to save image. Error code: " + error.Code }; alert.CancelButtonIndex = alert.AddButton("Ok"); alert.Show(); return; } UIGraphics.EndImageContext(); var pi = new ProjectImage { ProjectId = project.Id, Path = path, ThumbPath = thumbPath, Category = _category, Icon = _icon }; Data.Database.Main.Insert(pi); if (Success != null) Success(); }
public ProjectElement(Project p) : base(p.Name, "", UITableViewCellStyle.Value1) { Project = p; var count = Data.Database.Main.Table<ProjectImage>().Where(a => a.ProjectId == p.Id).Count(); this.Value = count.ToString(); }
public ProjectElement(Project p, UIViewController ctrl) : base(p.Name, "", UITableViewCellStyle.Value1) { Project = p; var count = Data.Database.Main.Table<ProjectImage>().Where(a => a.ProjectId == p.Id).Count(); this.Value = count.ToString(); if (Data.Database.Main.Table<ProjectImage>().Where(a => a.ProjectId == p.Id).Count() > 0) { this.Tapped += () => { ctrl.NavigationController.PushViewController(new LocalViewPatternsViewController(p.Id) { Title = p.Name }, true); }; } }