public ImageViewModel TryLoadImage() { OpenFileDialog fileDialog = new OpenFileDialog() { CheckFileExists = true, CheckPathExists = true, Multiselect = true, Filter = "JPG Files (*.jpg)|*.jpg|JPEG Files (*.jpeg)|*.jpeg|PNG Files (*.png)|*.png" }; Func<string, bool> isValidFile = file => { string[] extensions = { ".jpg", ".png", ".jpeg" }; string ext = Path.GetExtension(file); return extensions.Contains(ext); }; fileDialog.FileOk += (sender, args) => { if (!fileDialog.FileNames.All(isValidFile)) args.Cancel = true; }; bool? dialogResult = fileDialog.ShowDialog(); if (dialogResult.HasValue && dialogResult.Value) { try { Stream[] files = fileDialog.OpenFiles(); for (int i = 0; i < fileDialog.FileNames.Length; i++) { string filePath = fileDialog.FileNames[i]; Stream file = files[i]; byte[] fileData = null; using (var stream = new MemoryStream()) { file.CopyTo(stream); fileData = stream.ToArray(); } ImageViewModel viewModel = new ImageViewModel(0, Path.GetFileName(filePath), fileData); return viewModel; } } catch (Exception ex) { } } return null; }
private FileData FromImageViewModel(ImageViewModel image) { return image.Return(x => new FileData() { Id = x.Id, Data = x.Data }, null); }
public TemplateViewModel(int id, string name, IEnumerable<TemplateImageData> templateImages, ImageViewModel background, ImageViewModel overlay, bool isInstaPrinterTemplate) { Id = id; Name = name; Background = background; Overlay = overlay; TemplateImages = new List<TemplateImageData>(templateImages); IsInstaPrinterTemplate = isInstaPrinterTemplate; }
public CompositionViewModel( string name, int id, TemplateViewModel template, ImageViewModel background, ImageViewModel overlay) { Name = name; Id = id; Template = template; Background = background; Overlay = overlay; }
private Image ImageFromImageViewModel(ImageViewModel image) { return image.Return(x => new Image() { Id = x.Id, Name = x.Name, //Data = new FileData() //{ // Id = x.Id, // Data = x.Data //} }, null); }
public virtual void SaveImage(ImageViewModel image) { try { Session session = _imageRepository.GetActiveSession() ?? _imageRepository.GetLastSession(); if (session == null) { if (_imageRepository.StartSession()) session = _imageRepository.GetActiveSession(); else { throw new Exception("Cannot start session"); } } string baseDir = AppDomain.CurrentDomain.BaseDirectory; DirectoryInfo info = !Directory.Exists(Path.Combine(baseDir, "Images")) ? Directory.CreateDirectory(Path.Combine(baseDir, "Images")) : new DirectoryInfo(Path.Combine(baseDir, "Images")); string currentSessionStartTime = session.StartTime.ToString("dd_MM_yyyy"); string subDirectoryPath = Path.Combine(info.FullName, string.Format("{0}_{1}", currentSessionStartTime, session.Id)); DirectoryInfo subDirectory = !Directory.Exists(subDirectoryPath) ? info.CreateSubdirectory(string.Format("{0}_{1}", currentSessionStartTime, session.Id)) : new DirectoryInfo(subDirectoryPath); string path = Path.Combine(subDirectory.FullName, string.Format("{0}.png", Guid.NewGuid())); File.WriteAllBytes(path, image.Data); Image imageDb = new Image() { Session = session, Name = image.Name, Path = path }; imageDb.Session = session; _imageRepository.AddImage(imageDb); _imageRepository.Commit(); } catch (Exception) { } }
public CheckableImageWrapper(ImageViewModel image) { Image = image; }
public override void Initialize() { ThemeSettingsDto settings = _settingsProvider.GetThemeSettings(); GoPreview(); if (settings == null) { BackToDefaultTheme(); return; } if (settings.BackgroundImage != null) _mainWindowImage = new ImageViewModel(settings.BackgroundImage); if (settings.OtherBackgroundImage != null) _otherWindowsImage = new ImageViewModel(settings.OtherBackgroundImage); _mainWindowBackgroundColor = settings.MainBackgroundColor; _mainWindowBorderColor = settings.MainBorderColor; _mainWindowForegroundColor = settings.MainForegroundColor; _otherWindowsBackgroundColor = settings.OtherBackgroundColor; _otherWindowsBorderColor = settings.OtherBorderColor; _otherWindowsForegroundColor = settings.OtherForegroundColor; _otherWindowsButtonColor = settings.OtherButtonColor; _otherWindowsForegroundButtonColor = settings.OtherForegroundButtonColor; _otherWindowsBackgroundCircleColor = settings.OtherBackgroundCircleColor; RaisePropertyChanged(() => MainWindowImage); RaisePropertyChanged(() => OtherWindowsImage); RaisePropertyChanged(() => MainWindowBackgroundColor); RaisePropertyChanged(() => MainWindowBorderColor); RaisePropertyChanged(() => MainWindowForegroundColor); RaisePropertyChanged(() => OtherWindowsBackgroundColor); RaisePropertyChanged(() => OtherWindowsBorderColor); RaisePropertyChanged(() => OtherWindowsForegroundColor); RaisePropertyChanged(() => OtherWindowsButtonColor); RaisePropertyChanged(() => OtherWindowsForegroundButtonColor); RaisePropertyChanged(() => OtherWindowsBackgroundCircleColor); }
public static ImageViewModel CreateDefaultBackground() { var data = new byte[] {}; using (var backgroundBitmap = new Bitmap(500, 500)) { using (var canvas = Graphics.FromImage(backgroundBitmap)) { var color = System.Drawing.Color.FromArgb(255, 55, 62, 70); var pen = new SolidBrush(color); canvas.FillRectangle(pen, 0, 0, 500, 500); } try { using (var ms = new MemoryStream()) { backgroundBitmap.Save(ms, ImageFormat.Png); data = ms.ToArray(); } } catch (Exception e) { } } var background = new ImageViewModel(data); return background; }