private ImageSource PlatedImage(BitmapImage image) { if (!string.IsNullOrEmpty(BackgroundColor) && BackgroundColor != "transparent") { var width = image.Width; var height = image.Height; var x = 0; var y = 0; var group = new DrawingGroup(); var converted = ColorConverter.ConvertFromString(BackgroundColor); if (converted != null) { var color = (Color)converted; var brush = new SolidColorBrush(color); var pen = new Pen(brush, 1); var backgroundArea = new Rect(0, 0, width, width); var rectabgle = new RectangleGeometry(backgroundArea); var rectDrawing = new GeometryDrawing(brush, pen, rectabgle); group.Children.Add(rectDrawing); var imageArea = new Rect(x, y, image.Width, image.Height); var imageDrawing = new ImageDrawing(image, imageArea); group.Children.Add(imageDrawing); // http://stackoverflow.com/questions/6676072/get-system-drawing-bitmap-of-a-wpf-area-using-visualbrush var visual = new DrawingVisual(); var context = visual.RenderOpen(); context.DrawDrawing(group); context.Close(); const int dpiScale100 = 96; var bitmap = new RenderTargetBitmap( Convert.ToInt32(width), Convert.ToInt32(height), dpiScale100, dpiScale100, PixelFormats.Pbgra32 ); bitmap.Render(visual); return(bitmap); } else { Log.Error($"Can't convert background string <{BackgroundColor}> to color, Package location: <{Package.Location}>."); return(new BitmapImage(new Uri(Constant.ErrorIcon))); } } else { // todo use windows theme as background return(image); } }
public void ShowMidPoint() { DrawingGroup dg = new DrawingGroup(); ImageDrawing id = new ImageDrawing(UnderlayImage, new Rect(0, 0, UnderlayImage.PixelWidth, UnderlayImage.PixelHeight)); dg.Children.Add(id); GeometryDrawing gd1 = new GeometryDrawing(Brushes.Red, null, middlePointGeoGrp); dg.Children.Add(gd1); DrawingImage di = new DrawingImage(dg); this.Source = di; }
private void imgBox_PaintBackBuffer(object sender, IntPtr buf, int bw, int bh) { ImageDrawing id = imgBox.GetImageDrawing(buf, bw, bh); if (lbxDrawTest.SelectedIndex == 1) { ImageDrawingShape(id); } else if (lbxDrawTest.SelectedIndex == 3) { ImageDrawingRepeat(id); } }
/// <summary> /// Returns the image for the supplied gate (not currently used) /// </summary> /// <param name="gate"></param> /// <param name="point"></param> private ImageDrawing GetGateImage(Gate gate, System.Windows.Point point) { // Create our image ImageDrawing gateImage = new ImageDrawing(); string uriString = "Gate Images\\"; uriString += gate.GateType; uriString += ".gif"; gateImage.ImageSource = new BitmapImage(new Uri(AppDomain.CurrentDomain.BaseDirectory + uriString)); //gateImage.Rect = new Rect(point, new System.Windows.Size(GateWidth, GateHeight)); return(gateImage); }
//forWithResource public RectangleWithImage(string name, string resourceName) : base(name) { ImportImage = new Image(); ImgDraw = new ImageDrawing(); FrameworkElement seasherResource = new FrameworkElement(); ImgDraw.ImageSource = (seasherResource.FindResource(resourceName) as Image).Source; ResourceName = resourceName; DrawingImage drawImage = new DrawingImage(ImgDraw); ImportImage.Source = drawImage; base.ThinknessVisualObject = 1; }
public MapViewModel() { boothMap = new BoothMap(); overlay = new DrawingGroup(); baseMap = new ImageDrawing(); DrawingGroup mapDrawing = new DrawingGroup(); mapDrawing.Children.Add(baseMap); mapDrawing.Children.Add(overlay); drawnBooths = new HashSet <BoothWrapper>(); this.mapImage = new DrawingImage(mapDrawing); this.populateFromModel(); this.clickSetting = ClickSetting.Add; }
public void AddImage(string path, TileMode tile = TileMode.None, Rect?targetArea = null, Stretch stretch = Stretch.Fill, Rectangle rect = null, UriKind kind = UriKind.Relative) { BitmapImage bm = new BitmapImage(new Uri(path, kind)); UIElement el = null; if (tile != TileMode.None && rect == null) { Rectangle r = new Rectangle(); if (targetArea.HasValue) { r.Width = targetArea.Value.Width; r.Height = targetArea.Value.Height; } else { r.Width = this.ActualWidth; r.Height = this.ActualHeight; } Rect rr = new Rect(); rr.Width = bm.PixelWidth; rr.Height = bm.PixelHeight; ImageDrawing d = new ImageDrawing(bm, rr); DrawingBrush brush = new DrawingBrush(d); brush.Viewport = rr; brush.ViewportUnits = BrushMappingMode.Absolute; brush.TileMode = tile; brush.Stretch = Stretch.Fill; r.Fill = brush; el = r; } else { Image img = new Image(); img.Width = bm.Width; img.Height = bm.Height; img.Source = bm; el = img; } RenderCanvas.Children.Add(el); if (targetArea.HasValue) { Canvas.SetLeft(el, targetArea.Value.X); Canvas.SetTop(el, targetArea.Value.Y); } else { Canvas.SetLeft(el, 0); Canvas.SetTop(el, 0); } }
RenderTargetBitmap RenderFrame(int frameNumber, TimeSpan pts, double duration, Noise noise, Fade fade) { if (_mode == RenderMode.MontyPython) { var buffer = new RenderTargetBitmap(7680, 4320, 384.0, 384.0, PixelFormats.Pbgra32); var visual = ComposeVisual(pts, duration); visual.SnapsToDevicePixels = false; visual = noise.ApplyTo(visual); visual = fade.ApplyTo(frameNumber, visual); visual.Measure(new Size(1920, 1080)); visual.Arrange(new Rect(0, 0, 1920, 1080)); buffer.Render(visual); var bufferElement = new ImageDrawing(buffer, new Rect(0, 0, 1920, 1080)); var bufferVisual = new DrawingVisual(); RenderOptions.SetBitmapScalingMode(bufferElement, BitmapScalingMode.HighQuality); using (var context = bufferVisual.RenderOpen()) context.DrawDrawing(bufferElement); var target = new RenderTargetBitmap(1920, 1080, 96.0, 96.0, PixelFormats.Pbgra32); target.Render(bufferVisual); return(target); } else { var target = new RenderTargetBitmap(1920, 1080, 96.0, 96.0, PixelFormats.Pbgra32); var visual = ComposeVisual(pts, duration); visual = noise.ApplyTo(visual); visual = fade.ApplyTo(frameNumber, visual); visual.Measure(new Size(1920, 1080)); visual.Arrange(new Rect(0, 0, 1920, 1080)); target.Render(visual); return(target); } }
/// <summary> /// Draws out a Pause screen. /// </summary> /// <returns>A drawing.</returns> private Drawing GetPauseScreen() { if (!this.model.GameIsPaused) { return(new ImageDrawing()); } if (this.model.GameIsPaused) { ImageDrawing drawing = new ImageDrawing(GetImage("stopped2.png"), new Rect(0, 0, this.model.GameWidth, this.model.GameHeight)); this.oldPauseScreen = drawing; } return(this.oldPauseScreen); }
private Drawing GetExplosions() { DrawingGroup dg = new DrawingGroup(); foreach (var item in this.model.Enemies) { if (item.IsShooted) { ImageDrawing box = new ImageDrawing(GetImage("enemy_explosion.png"), new Rect(item.X, item.Y, 140, 140)); dg.Children.Add(box); } } this.explosion = dg; return(this.explosion); }
/// <summary> /// Draws out the rocks. /// </summary> /// <returns>a drawing.</returns> private Drawing GetWalls() { if (this.oldWalls == null) { DrawingGroup g = new DrawingGroup(); foreach (var wall in this.model.Walls) { ImageDrawing drawing = new ImageDrawing(GetImage("rock100.png"), new Rect(wall.Cords.X * GameModel.TileSize, wall.Cords.Y * GameModel.TileSize, GameModel.TileSize, GameModel.TileSize)); g.Children.Add(drawing); } this.oldWalls = g; } return(this.oldWalls); }
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; }
private Drawing GetEnemyBullets() { DrawingGroup dg = new DrawingGroup(); foreach (var item in this.model.EnemyBullets) { if (this.bullet == null || !this.oldBulletPositions.Select(x => x.Y).Contains(item.Y)) { ImageDrawing box = new ImageDrawing(GetImage("enemy_laser.png"), new Rect(item.X, item.Y, 50, 50)); dg.Children.Add(box); } } this.bullet = dg; return(this.bullet); }
/// <summary> /// Draws out the lavas. /// </summary> /// <returns>a drawing.</returns> private Drawing GetLavas() { if (this.oldLavas == null) { DrawingGroup g = new DrawingGroup(); foreach (var lava in this.model.Lavas) { ImageDrawing drawing = new ImageDrawing(GetImage("lava.png"), new Rect(lava.Cords.X * GameModel.TileSize, lava.Cords.Y * GameModel.TileSize, GameModel.TileSize, GameModel.TileSize)); g.Children.Add(drawing); } this.oldLavas = g; } return(this.oldLavas); }
static void RenderTo(this ImageDrawing drawing, d.Graphics graphics, double opacity) { var image = drawing.ImageSource.ToGdiPlus(); if (image != null) { var ia = new di.ImageAttributes(); ia.SetColorMatrix(new di.ColorMatrix { Matrix33 = (float)opacity }); var r = drawing.Rect; graphics.DrawImage(image, new[] { r.TopLeft.ToGdiPlus(), r.TopRight.ToGdiPlus(), r.BottomLeft.ToGdiPlus() }, new d.RectangleF(0, 0, image.Width, image.Height), d.GraphicsUnit.Pixel, ia); } }
private void saveFileMenuItem_Click(object sender, RoutedEventArgs e) { DrawingImage drawingImageSource = Render(); drawingImageSource.Freeze(); ImageDrawing a = new ImageDrawing(drawingImageSource, new Rect(new System.Windows.Size(drawingImageSource.Width, drawingImageSource.Height))); SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "PNG (*.png)|*.png|JPG (*.jpg)|*.jpg|GIF (*.gif)|*.gif"; if (saveFileDialog.ShowDialog() == true) { SaveDrawingToFile(a, saveFileDialog.FileName, 1); } }
public static DrawingGroup CreateBaseImage(Base baze, String url, bool withShader = true) { DrawingGroup g = null; baze.SceneMgr.Invoke(new Action(() => { BitmapImage bi = new BitmapImage(); bi.BeginInit(); bi.UriSource = new Uri(url); bi.EndInit(); g = new DrawingGroup(); ImageDrawing img = new ImageDrawing(); img.Rect = new Rect(baze.Size); if (withShader) { ColorReplaceEffect effect = new ColorReplaceEffect(); effect.ColorToOverride = Colors.White; effect.ColorReplace = baze.Owner.GetPlayerColor(); RenderTargetBitmap rtb = new RenderTargetBitmap((int)baze.Size.Width * 2, (int)baze.Size.Height * 2, 96, 96, PixelFormats.Pbgra32); System.Windows.Shapes.Rectangle visual = new System.Windows.Shapes.Rectangle(); visual.Fill = new ImageBrush(bi); visual.Effect = effect; Size sz = new Size(baze.Size.Width * 2, baze.Size.Height * 2); visual.Measure(sz); visual.Arrange(new Rect(sz)); rtb.Render(visual); img.ImageSource = rtb; } else { img.ImageSource = bi; } TransformGroup tg = new TransformGroup(); tg.Children.Add(new TranslateTransform(baze.Position.X, baze.Position.Y)); g.Transform = tg; g.Children.Add(img); })); return(g); }
public static ImageDrawing MatToImageDrawing(Mat mat, Rect drawingRect) { BitmapSource source; using (Bitmap bitmap = mat.Bitmap) { IntPtr ptr = bitmap.GetHbitmap(); source = Imaging.CreateBitmapSourceFromHBitmap( ptr, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); } ImageDrawing imageDrawing = new ImageDrawing(source, drawingRect); return(imageDrawing); }
private void DrawExperience(ImDrawListPtr drawList, int experience, int maxExp) { int size = (int)Math.Ceiling(256 * Ui.Configuration.Scale); var drawPosition = ImGui.GetItemRectMin() + new Vector2(0, (int)HealthY); ExperienceRingBg.Draw(drawList, 1, drawPosition, 4, Ui.Configuration.Scale); ExperienceRing.Draw(drawList, experience / (float)maxExp, drawPosition, 4, Ui.Configuration.Scale); drawList.PushClipRect(drawPosition, drawPosition + new Vector2(size, size)); drawList.AddImage(RingExperienceBgTexture.ImGuiHandle, drawPosition, drawPosition + new Vector2(size, size)); drawList.PopClipRect(); int iconSize = 64; ImageDrawing.DrawIcon(Pi, drawList, (ushort)(62000 + Pi.ClientState.LocalPlayer.ClassJob.Id), new Vector2(iconSize, iconSize), new Vector2((int)(size / 2f - iconSize / 2f), (int)(size / 2f - iconSize / 2f)) + new Vector2(0, (int)HealthY)); }
private Drawing GetEnemies() { DrawingGroup dg = new DrawingGroup(); foreach (var item in this.model.Enemies) { if (this.enemy == null || !this.oldEnemyPositions.Select(x => x.Y).Contains(item.Y)) { ImageDrawing box = new ImageDrawing(GetImage("enemy_1.png"), new Rect(item.X, item.Y, 140, 140)); dg.Children.Add(box); } } this.enemy = dg; return(this.enemy); }
private void ImageDrawingShape(ImageDrawing id) { id.DrawLine(Color.Red, 0, 0, 8, 8); id.DrawRectangle(Color.Red, 8, 8, 4, 4); id.DrawRectangle(Color.Red, 16.5f, 16.5f, 4f, 4f); var text = tbxExample.Text; var font = (IFont)cbxFont.SelectedValue; id.DrawString(text, font, Color.Blue, 50, 50); id.DrawString(text, font, Color.Blue, 200, 200, Color.Yellow); for (int i = 0; i < 100; i += 5) { id.DrawPixel(Color.Yellow, 150 + i, 150); } }
public MainWindow() { InitializeComponent(); string path = @"D:\ブログ用\チェック用2\WP_20210228_11_25_51_Pro_2021_02_28_午後わてん.jpg"; path = @"D:\ブログ用\テスト用画像\border_row.bmp"; BitmapImage bmpImage = new BitmapImage(new Uri(path)); //bmpImage.Freeze();//必須、しないとエラー MyStackPanel.Children.Add(new Image() { Source = bmpImage, Stretch = Stretch.None }); //BitmapSource系からImageDrawing作成 //ImageDrawingからDrawingImage作成 //DrawingImageをImageのSourceにして表示 //表示はできるけど、このまま画像取得はできない ImageDrawing id = new ImageDrawing(bmpImage, new Rect(0, 0, 100, 100)); DrawingImage di = new DrawingImage(id); MyStackPanel.Children.Add(new Image() { Source = di, Stretch = Stretch.None }); Image img = new Image() { Source = di }; ImageSource source = img.Source; //DrawingVisualとRenderTargetBitmapを使って画像取得 //できるけど、これならBitmapImageから直接取得変形したほうが早い var dv = new DrawingVisual(); using (var dc = dv.RenderOpen()) { dc.DrawImage(di, new Rect(0, 0, 100, 100)); //これはエラー //dc.DrawImage(id, new Rect(0, 0, 100, 100)); } var rtb = new RenderTargetBitmap(100, 100, 96, 96, PixelFormats.Pbgra32); rtb.Render(dv); }
private static void SwapColorsWithoutCloning(Drawing drawing, ColorCallback colorCallback) { if (drawing != null) { DrawingGroup group = drawing as DrawingGroup; if (group != null) { for (int i = 0; i < group.Children.Count; i++) { SwapColorsWithoutCloning(group.Children[i], colorCallback); } } else { GeometryDrawing drawing2 = drawing as GeometryDrawing; if (drawing2 != null) { SwapColorsWithoutCloning(drawing2.Brush, colorCallback); if (drawing2.Pen != null) { SwapColorsWithoutCloning(drawing2.Pen.Brush, colorCallback); } } else { GlyphRunDrawing drawing3 = drawing as GlyphRunDrawing; if (drawing3 != null) { SwapColorsWithoutCloning(drawing3.ForegroundBrush, colorCallback); } else { ImageDrawing drawing4 = drawing as ImageDrawing; if (drawing4 != null) { drawing4.ImageSource = SwapColorsWithoutCloningIfPossible(drawing4.ImageSource, colorCallback); } else if (!(drawing is VideoDrawing)) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "UnexpectedDrawingType", new object[] { drawing.GetType().Name })); } } } } } }
public static void CreateSaveBitmap(Canvas canvas1, Canvas canvas2, string filename) { RenderTargetBitmap renderBitmap1 = new RenderTargetBitmap((int)canvas1.ActualWidth, (int)canvas1.ActualHeight, 96d, 96d, PixelFormats.Pbgra32); canvas1.Measure(new Size((int)canvas1.ActualWidth, (int)canvas1.ActualHeight)); canvas1.Arrange(new Rect(new Size((int)canvas1.ActualWidth, (int)canvas1.ActualHeight))); renderBitmap1.Render(canvas1); RenderTargetBitmap renderBitmap2 = new RenderTargetBitmap((int)canvas2.ActualWidth, (int)canvas2.ActualHeight, 96d, 96d, PixelFormats.Pbgra32); canvas2.Measure(new Size((int)canvas2.ActualWidth, (int)canvas2.ActualHeight)); canvas2.Arrange(new Rect(new Size((int)canvas2.ActualWidth, (int)canvas2.ActualHeight))); renderBitmap2.Render(canvas2); //Combine the images here var dg = new DrawingGroup(); var id1 = new ImageDrawing(renderBitmap1, new Rect(0, 0, renderBitmap1.Width, renderBitmap1.Height)); var id2 = new ImageDrawing(renderBitmap2, new Rect(0, 0, renderBitmap2.Width, renderBitmap2.Height)); dg.Children.Add(id1); dg.Children.Add(id2); var combinedImg = new RenderTargetBitmap((int)(renderBitmap1.Width + 0.5), (int)(Math.Max(renderBitmap1.Height, renderBitmap2.Height) + 0.5), 96, 96, PixelFormats.Pbgra32); var dv = new DrawingVisual(); using (var dc = dv.RenderOpen()) { dc.DrawDrawing(dg); } combinedImg.Render(dv); //JpegBitmapEncoder encoder = new JpegBitmapEncoder(); PngBitmapEncoder encoder = new PngBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(combinedImg)); using (FileStream file = File.Create(filename)) { encoder.Save(file); } }
private void UpdateDebugInfo(object sender, EventArgs e) { if (m_bWaitThread && Singleton <BusinessLogic> .Instance.ThreadHasFinished()) { m_bWaitThread = false; Info.Content = "完成"; m_timer.Stop(); m_timer = null; // 随便画画 DrawingGroup imageDrawings = new DrawingGroup(); Card[] cards = Singleton <CardRepository> .Instance.Cards; for (int i = 0; i < cards.Length; ++i) { ImageDrawing image = new ImageDrawing(); image.Rect = new Rect(i * 50, 50, 150, 200); image.ImageSource = new BitmapImage(new Uri(cards[i].ImagePath, UriKind.Relative)); imageDrawings.Children.Add(image); } DrawingImage drawingImageSource = new DrawingImage(imageDrawings); drawingImageSource.Freeze(); Image imageControl = new Image(); imageControl.Stretch = Stretch.None; imageControl.Source = drawingImageSource; Border imageBorder = new Border(); imageBorder.BorderBrush = Brushes.Gray; imageBorder.BorderThickness = new Thickness(1); imageBorder.HorizontalAlignment = HorizontalAlignment.Left; imageBorder.VerticalAlignment = VerticalAlignment.Top; imageBorder.Margin = new Thickness(20); imageBorder.Child = imageControl; CardsBrowser.Content = imageBorder; } else { Info.Content = m_strMsg; } }
/// <summary> /// Draws out all the flying enemies. /// </summary> /// <returns>a drawing.</returns> private Drawing GetFlyingMonsters() { DrawingGroup g = new DrawingGroup(); foreach (var enemy in this.model.FlyingMonsters) { if (this.oldFlyingMonsters == null || !this.oldFlyingMonstersPosition.Contains(enemy.Cords)) { BitmapImage bmp = GetImage("missle100.png"); TransformedBitmap tb = new TransformedBitmap(); tb.BeginInit(); tb.Source = bmp; switch (this.model.FlyingTrackingPath[enemy.Cords]) { case { } point when point == new Point(1, 0): tb.Transform = new RotateTransform(90); break; case { } point when point == new Point(0, 1): tb.Transform = new RotateTransform(180); break; case { } point when point == new Point(-1, 0): tb.Transform = new RotateTransform(270); break; case { } point when point == new Point(0, -1): tb.Transform = new RotateTransform(0); break; default: break; } tb.EndInit(); ImageDrawing drawing = new ImageDrawing(tb, new Rect(enemy.Cords.X * GameModel.TileSize, enemy.Cords.Y * GameModel.TileSize, GameModel.TileSize, GameModel.TileSize)); g.Children.Add(drawing); } } this.oldFlyingMonsters = g; return(this.oldFlyingMonsters); }
private Drawing GetBlocks() { if (this.oldBlocks == null) { DrawingGroup dg = new DrawingGroup(); foreach (var block in this.model.Blocks) { ImageDrawing blockPic = new ImageDrawing(GetImage("block.png"), new Rect(block.CX, block.CY / 2 * 3, this.model.GameDisplayWidth / 5, this.model.GameDisplayHeight / 4)); // Geometry b = new RectangleGeometry(new Rect(block.CX, block.CY / 2 *3, model.GameDisplayWidth/5, model.GameDisplayHeight/4)); dg.Children.Add(blockPic); } this.oldBlocks = dg; } return(this.oldBlocks); }
private void DrawDashboard(DrawingGroup dg, int x, int y) { var levenImageSource = Resources.GetImage("SenneGameWpf", "images/smiley Angry.png"); for (var i = 0; i < _life; i++) { var leven = new ImageDrawing(levenImageSource, new Rect(10 * i + x, y, 10, 10)); dg.Children.Add(leven); } var ammodrawing = DrawText(x, y + 10, string.Format("AMMO: {0}", _ammo)); dg.Children.Add(ammodrawing); var pointsdrawing = DrawText(x, y + 20, string.Format("POINTS: {0}", _points)); dg.Children.Add(pointsdrawing); }
public ImageDrawing GetByID(int id, Point startPoint) { Point topLeftTile = GetPointByID(id); Size sizeOfTile = GetTileSize(); RectangleGeometry geometry = new RectangleGeometry(new Rect(topLeftTile, sizeOfTile)); Mat croppedImage = BrushUtils.CropImage(this.MatImage, topLeftTile, sizeOfTile); if (this.IsTransparent.Value) { croppedImage = ImageUtils.ColorToTransparent(croppedImage, this.TransparentColor.Value); } Rect drawingRect = new Rect(startPoint, sizeOfTile); ImageDrawing drawing = ImageUtils.MatToImageDrawing(croppedImage, drawingRect); return(drawing); }
public ImageDrawing add_unit_img(BitmapImage bi, int x, int y) { int draw_width = Convert.ToInt32(bi.Width); int draw_height = Convert.ToInt32(bi.Height); int drawX = x - (draw_width / 2); int drawY = y - (draw_height / 2); Rect r = new Rect(drawX, drawY, draw_width, draw_height); ImageDrawing img_d = new ImageDrawing(bi, r); _drawingGroup.Children.Add(img_d); is_dirt = true; return(img_d); }