/// <summary> /// Creates the alpha mask with the tiled image. /// </summary> /// <returns>The brush to use for masking.</returns> private static ImageBrush CreateTileImageMask() { ImageSource tileImage = LookAndFeel.TileImage; var drawings = new DrawingGroup(); // TODO: Get from image. var imageWidth = 172; var imageHeight = 100; for (var x = 0; x < (maxScreenWidth / imageWidth) + 1; x++) { for (var y = 0; y < (maxScreenHeight / imageHeight) + 1; y++) { var drawing = new ImageDrawing(); drawing.Rect = new Rect(x * imageWidth, y * imageHeight, imageWidth, imageHeight); drawing.ImageSource = tileImage; drawing.Freeze(); drawings.Children.Add(drawing); } } drawings.Freeze(); var mask = new DrawingImage(drawings); mask.Freeze(); var maskBrush = new ImageBrush(mask); maskBrush.Freeze(); return(maskBrush); }
public WindowOverlayHelper() { Loaded += OnWindowLoaded; Unloaded += OnWindowUnloaded; WindowState = WindowState.Maximized; WindowStyle = WindowStyle.None; AllowsTransparency = true; Background = Brushes.Transparent; Topmost = true; Fullscreen = true; IsTopmost = true; var reticleDrawing = new ImageDrawing(); reticleDrawing.Rect = new Rect(0, 0, 33, 33); reticleDrawing.ImageSource = new BitmapImage(new Uri(@"Resources\Reticle.png", UriKind.Relative)); reticleDrawing.Freeze(); DrawingImage drawImage = new DrawingImage(reticleDrawing); reticle = new Image { Stretch = Stretch.None, Source = drawImage, Visibility = Visibility.Hidden }; canvasArea = new Canvas(); canvasArea.Children.Add(reticle); this.AddChild(canvasArea); }
public void add_ground_img(BitmapImage bi, Rect r) { int x = (int)r.X / 32; int y = (int)r.Y / 32; ImageDrawing img_d = new ImageDrawing(bi, r); img_d.Freeze(); if (ground_imgDrawing[x, y] != null) { delete_ground_img(ground_imgDrawing[x, y]); } _drawingGroup.Children.Add(img_d); ground_imgDrawing[x, y] = img_d; is_dirt = true; }
public void add_ground_img(ImageSource bi, Rect r) { int x = (int)r.X / 32 / cells_in_rect_x; int y = (int)r.Y / 32 / cells_in_rect_y; r.X -= x * 32 * cells_in_rect_x; r.Y -= y * 32 * cells_in_rect_y; ImageDrawing img_d = new ImageDrawing(bi, r); img_d.Freeze(); dc = dv.RenderOpen(); dc.DrawDrawing(img_d); dc.Close(); rtbs[x, y].Render(dv); img_d = null; //GC.Collect(0); }
/// <summary> /// Merges the Protocol-Icon with the overlays and returns the merged Icon /// </summary> private void GenerateDisplayIcon() { if (ConnectionIcon == null) { return; } if (ConnectionIconOverlays.Count == 0) { DisplayIcon = ConnectionIcon; return; } DrawingImage finalIcon = null; //Dispatcher.BeginInvoke(new Action(() => Application.Current.Dispatcher.Invoke(() => { var dGr = new DrawingGroup(); var newGroupItem = new ImageDrawing(ConnectionIcon, new Rect(0, 0, 16, 16)); newGroupItem.Freeze(); dGr.Children.Add(newGroupItem); foreach (var anOverlay in ConnectionIconOverlays) { dGr.Children.Add(new ImageDrawing(anOverlay, new Rect(0, 0, 16, 16))); } dGr.Freeze(); finalIcon = new DrawingImage(dGr); finalIcon.Freeze(); }); DisplayIcon = finalIcon; }
/// <summary> /// Recreates the window mask. /// </summary> private void RecreateWindowMask() { Rect windowRect = GetWindowShape(); double width = windowRect.Width; double height = windowRect.Height; double left = windowRect.X; double top = windowRect.Y; // Add top left and bottom right marker so the final image will have the size of the screen. Rect[] rects = new Rect[] { new Rect(0, 0, 1, 1), new Rect(maxScreenWidth - 1, maxScreenHeight - 1, 1, 1), new Rect(left, top, 20, 60), new Rect(left + width - 20, top, 20, 60), new Rect(left, top + height - 60, 20, 60), new Rect(left + width - 20, top + height - 60, 20, 60), new Rect(left + 20, top, Math.Max(0, width - 40), height), new Rect(left, top + 60, width, Math.Max(0, height - 120)), }; var drawings = new DrawingGroup(); for (var i = 0; i < rects.Length; i++) { ImageDrawing drawing = new ImageDrawing(); drawing.Rect = rects[i]; drawing.ImageSource = windowImages[i]; drawings.Children.Add(drawing); } var windowImage = new DrawingImage(drawings); // Improve performance by freezing. windowImage.Freeze(); var maskDrawing = new ImageDrawing(windowImage, new Rect(-(maxScreenWidth - width) / 2, -(maxScreenHeight - height) / 2, maxScreenWidth, maxScreenHeight)); maskDrawing.Freeze(); windowMaskBrush = new DrawingBrush(maskDrawing); windowMaskBrush.Freeze(); }
public void InitLandPalette(Scena scn) { int w = tiles_collumns_count; int h = scn.tileSet.Count / tiles_collumns_count; if (scn.tileSet.Count % tiles_collumns_count != 0) { h++; } //w *= 32; //h *= 32; DrawingGroup imageDrawings = new DrawingGroup(); scn.Mega_bmp = new DrawingImage(imageDrawings); ImageDrawing img_d; for (int j = 0; j < h; j++) { for (int i = 0; i < w; i++) { if (scn.tileSet.Count > j * tiles_collumns_count + i) { System.Windows.Rect r = new System.Windows.Rect(i * 32, j * 32, 32, 32); img_d = new ImageDrawing(scn.tileSet[j * tiles_collumns_count + i].Sprite, r); img_d.Freeze(); imageDrawings.Children.Add(img_d); } } } Gl.main.Ground_Pallete_Image.Source = scn.Mega_bmp; Gl.main.Ground_Pallete_Canvas.Height = scn.Mega_bmp.Height; }
private DrawingImage DrawPreview(HistoryItem item) { DrawingGroup drawingGroup = new DrawingGroup(); // Background: Product image BitmapImage image = new BitmapImage(new Uri(currentItem.ImageSource, UriKind.Relative)); ImageDrawing imageDrawing = new ImageDrawing(image, new Rect(0, 0, image.Width, image.Height)); imageDrawing.Freeze(); drawingGroup.Children.Add(imageDrawing); // Rectangle in the center GeometryDrawing rectangle = new GeometryDrawing(); double rectRatio = 0.5; double rectWidth = image.Width * rectRatio; double rectHeight = image.Height * rectRatio; double rectX = (image.Width - rectWidth) / 2; double rectY = (image.Height - rectHeight) / 2; var rectangleBrush = new SolidColorBrush(Colors.Gray); rectangleBrush.Opacity = 0.7; rectangle.Brush = rectangleBrush; rectangle.Geometry = new RectangleGeometry(new Rect(rectX, rectY, rectWidth, rectHeight)); drawingGroup.Children.Add(rectangle); double fontSize = image.Width * 0.08; double lineHeight = fontSize * 1.2; double textX = rectX + fontSize / 10; double textY = rectY + lineHeight / 10; // Text inside rectangle DrawingVisual visual = new DrawingVisual(); using (var context = visual.RenderOpen()) { context.DrawText(new FormattedText(item.TimeStamp.ToString("dd/MM/yyyy") , CultureInfo.InvariantCulture , FlowDirection.LeftToRight , new Typeface("Arial") , fontSize , Brushes.White , VisualTreeHelper.GetDpi(this).PixelsPerDip), new Point(textX, textY)); context.DrawText(new FormattedText((!string.IsNullOrEmpty(item.OldPrice)? item.OldPrice + " => " : "") + item.NewPrice , CultureInfo.InvariantCulture , FlowDirection.LeftToRight , new Typeface("Arial") , fontSize , Brushes.White , VisualTreeHelper.GetDpi(this).PixelsPerDip), new Point(textX, textY + lineHeight)); if (!string.IsNullOrEmpty(item.Note)) { context.DrawText(new FormattedText(item.Note , CultureInfo.InvariantCulture , FlowDirection.LeftToRight , new Typeface("Arial") , fontSize , Brushes.White , VisualTreeHelper.GetDpi(this).PixelsPerDip), new Point(textX, textY + 2 * lineHeight)); } } drawingGroup.Children.Add(visual.Drawing); DrawingImage drawingImage = new DrawingImage(drawingGroup); return(drawingImage); }