public void Draw(LayerModel layer, DrawingContext c) { var props = (KeyboardPropertiesModel)layer.Properties; if (string.IsNullOrEmpty(props.GifFile)) { return; } if (!File.Exists(props.GifFile)) { return; } // Only reconstruct GifImage if the underlying source has changed if (layer.GifImage == null) { layer.GifImage = new GifImage(props.GifFile); } if (layer.GifImage.Source != props.GifFile) { layer.GifImage = new GifImage(props.GifFile); } var rect = new Rect(layer.AppliedProperties.X * 4, layer.AppliedProperties.Y * 4, layer.AppliedProperties.Width * 4, layer.AppliedProperties.Height * 4); lock (layer.GifImage) { var draw = layer.GifImage.GetNextFrame(); c.DrawImage(ImageUtilities.BitmapToBitmapImage(new Bitmap(draw)), rect); } }
public PreviewSettings(Rect overlayRectangle, Bitmap bitmap) { OverlayRectangle = overlayRectangle; BackgroundRectangle = new Rect(0, 0, bitmap.Width, bitmap.Height); Image = ImageUtilities.BitmapToBitmapImage(bitmap); Image.Freeze(); }
public static ImageSource DrawThumbnail(LayerModel layerModel) { var thumbnailRect = new Rect(0, 0, 18, 18); var visual = new DrawingVisual(); using (var c = visual.RenderOpen()) { // Draw the appropiate icon or draw the brush if (layerModel.LayerType == LayerType.Folder) { c.DrawImage(ImageUtilities.BitmapToBitmapImage(Resources.folder), thumbnailRect); } else if (layerModel.LayerType == LayerType.Headset) { c.DrawImage(ImageUtilities.BitmapToBitmapImage(Resources.headset), thumbnailRect); } else if (layerModel.LayerType == LayerType.Mouse) { c.DrawImage(ImageUtilities.BitmapToBitmapImage(Resources.mouse), thumbnailRect); } else if (layerModel.LayerType == LayerType.KeyboardGif) { c.DrawImage(ImageUtilities.BitmapToBitmapImage(Resources.gif), thumbnailRect); } else if (layerModel.LayerType == LayerType.Keyboard && layerModel.Properties.Brush != null) { c.DrawRectangle(layerModel.Properties.Brush, new Pen(new SolidColorBrush(Colors.White), 1), thumbnailRect); } } var image = new DrawingImage(visual.Drawing); return(image); }
public static GifImage DrawGif(DrawingContext c, KeyboardPropertiesModel props, AppliedProperties applied, GifImage gifImage) { if (string.IsNullOrEmpty(props.GifFile)) { return(null); } if (!File.Exists(props.GifFile)) { return(null); } const int scale = 4; // Only reconstruct GifImage if the underlying source has changed if (gifImage == null) { gifImage = new GifImage(props.GifFile); } if (gifImage.Source != props.GifFile) { gifImage = new GifImage(props.GifFile); } var gifRect = new Rect(applied.X * scale, applied.Y * scale, applied.Width * scale, applied.Height * scale); lock (gifImage) { var draw = gifImage.GetNextFrame(); c.DrawImage(ImageUtilities.BitmapToBitmapImage(new Bitmap(draw)), gifRect); } return(gifImage); }
public ImageSource DrawThumbnail(LayerModel layer) { var thumbnailRect = new Rect(0, 0, 18, 18); var visual = new DrawingVisual(); using (var c = visual.RenderOpen()) c.DrawImage(ImageUtilities.BitmapToBitmapImage(Resources.ambilight), thumbnailRect); return(new DrawingImage(visual.Drawing)); }
public ImageTypeWrapper(ImageType type) { Name = type.Name; Id = type.Id; FilePath = type.Path; if (File.Exists(type.Path)) { BitmapImage = new BitmapImage(new Uri(type.Path)); } else { var bitmap = type.GetImage(); BitmapImage = ImageUtilities.BitmapToBitmapImage(bitmap); } }
public ProfileEditorViewModel(ProfileEditorModel profileEditorModel, DeviceManager deviceManager, LoopManager loopManager, LuaManager luaManager, ModuleModel moduleModel, MetroDialogService dialogService) { _deviceManager = deviceManager; _loopManager = loopManager; _moduleModel = moduleModel; _dialogService = dialogService; _copyKeybind = new KeybindModel("copy", new HotKey(Key.C, ModifierKeys.Control), PressType.Down, LayerToClipboard); _pasteKeybind = new KeybindModel("paste", new HotKey(Key.V, ModifierKeys.Control), PressType.Up, ClipboardToLayer); _placeholderKeyboard = KeyboardPreview = ImageUtilities.BitmapToBitmapImage(Resources.none); ProfileNames = new ObservableCollection <string>(); Layers = new ObservableCollection <LayerModel>(); ProfileEditorModel = profileEditorModel; LuaManager = luaManager; ShowAll = true; PropertyChanged += EditorStateHandler; _deviceManager.OnKeyboardChanged += DeviceManagerOnOnKeyboardChanged; _moduleModel.ProfileChanged += ModuleModelOnProfileChanged; LoadProfiles(); }