public static Brush CreateImageParticle(Color color, Uri source, int renderSize) { BitmapImage bi = new BitmapImage(); bi.BeginInit(); bi.UriSource = source; bi.EndInit(); AlphaMaskEffect effect = new AlphaMaskEffect(); effect.Color = color; RenderTargetBitmap rtb = PrepareRenderTarget(renderSize); System.Windows.Shapes.Rectangle visual = new System.Windows.Shapes.Rectangle(); visual.Fill = new ImageBrush(bi); visual.Effect = effect; Size sz = new Size(renderSize, renderSize); visual.Measure(sz); visual.Arrange(new Rect(sz)); rtb.Render(visual); return(new ImageBrush(rtb)); }
/// <summary>Creates the screenshot of entire plotter element</summary> /// <returns></returns> internal static BitmapSource CreateScreenshot(UIElement uiElement, Int32Rect screenshotSource) { Window window = Window.GetWindow(uiElement); if (window == null) { return CreateElementScreenshot(uiElement); } Size size = window.RenderSize; //double dpiCoeff = 32 / SystemParameters.CursorWidth; //int dpi = (int)(dpiCoeff * 96); double dpiCoeff = 1; int dpi = 96; RenderTargetBitmap bmp = new RenderTargetBitmap( (int)(size.Width * dpiCoeff), (int)(size.Height * dpiCoeff), dpi, dpi, PixelFormats.Default); // white background Rectangle whiteRect = new Rectangle { Width = size.Width, Height = size.Height, Fill = Brushes.White }; whiteRect.Measure(size); whiteRect.Arrange(new Rect(size)); bmp.Render(whiteRect); // the very element bmp.Render(uiElement); CroppedBitmap croppedBmp = new CroppedBitmap(bmp, screenshotSource); return croppedBmp; }
public static Brush CreateBaseImageParticle(Color color) { BitmapImage bi = new BitmapImage(); bi.BeginInit(); bi.UriSource = new Uri("pack://application:,,,/resources/images/particles/base-particle.png"); bi.EndInit(); ColorReplaceEffect effect = new ColorReplaceEffect(); effect.ColorToOverride = Colors.White; effect.ColorReplace = color; RenderTargetBitmap rtb = PrepareRenderTarget(128); System.Windows.Shapes.Rectangle visual = new System.Windows.Shapes.Rectangle(); visual.Fill = new ImageBrush(bi); visual.Effect = effect; Size sz = new Size(128, 128); visual.Measure(sz); visual.Arrange(new Rect(sz)); rtb.Render(visual); return(new ImageBrush(rtb)); }
public void MeasureTest1 () { Rectangle r = new Rectangle (); r.Width = 10; r.Height = 20; r.Measure (new Size (50, 50)); Assert.AreEqual (new Size (0, 0), r.DesiredSize); }
public void MeasureTest2 () { Canvas c = new Canvas (); Rectangle r = new Rectangle (); r.Width = 10; r.Height = 20; r.Measure (new Size (50, 50)); Assert.AreEqual (new Size (0, 0), r.DesiredSize); c.Children.Add (r); r.Measure (new Size (50, 50)); Assert.AreEqual (new Size (0, 0), r.DesiredSize); c.Measure (new Size (50, 50)); Assert.AreEqual (new Size (0, 0), c.DesiredSize, "Canvas desired"); Assert.AreEqual (new Size (0, 0), r.DesiredSize, "Rectangle desired"); }
public void MeasureTest3 () { Border c = new Border (); Rectangle r = new Rectangle (); r.Width = 10; r.Height = 20; r.Measure (new Size (50, 50)); Assert.AreEqual (new Size (0, 0), r.DesiredSize); c.Child = r; c.Measure (new Size (50, 50)); Assert.AreEqual (new Size (10, 20), c.DesiredSize, "Border desired"); Assert.AreEqual (new Size (10, 20), r.DesiredSize, "Rectangle desired"); }
public void MeasureTest2_1 () { Border b = new Border (); Canvas c = new Canvas (); Rectangle r = new Rectangle (); r.Width = 10; r.Height = 20; r.Measure (new Size (50, 50)); Assert.AreEqual (new Size (0, 0), r.DesiredSize); b.Child = c; c.Children.Add (r); b.Width = 20; b.Height = 10; b.Measure (new Size (50, 50)); Assert.AreEqual (new Size (0, 0), c.DesiredSize, "Canvas desired"); Assert.AreEqual (new Size (0, 0), r.DesiredSize, "Rectangle desired"); Assert.AreEqual (new Size (20, 10), b.DesiredSize, "Border desired"); }
static void Apply(Shader shader, BitmapImage bitmap, string destImage) { Rectangle r = new Rectangle (); r.Effect = shader; shader.Input = new ImageBrush (bitmap); /*The fill brush is ignored due to the effect been applied*/ r.Fill = new SolidColorBrush (Colors.Aquamarine); Size size = new Size (bitmap.PixelWidth, bitmap.PixelHeight); r.Measure (size); r.Arrange (new Rect (size)); RenderTargetBitmap render = new RenderTargetBitmap ( bitmap.PixelWidth, bitmap.PixelHeight, 96, 96, PixelFormats.Pbgra32); render.Render (r); PngBitmapEncoder png = new PngBitmapEncoder (); png.Frames.Add (BitmapFrame.Create (render)); using (Stream stm = File.Open (destImage, FileMode.OpenOrCreate)) { png.Save (stm); } }
protected override void CreateHeatMap() { intensityMap = new RenderTargetBitmap(500, 500, 96, 96, PixelFormats.Pbgra32); AddativeBlendClear cleareffect = new AddativeBlendClear(); cleareffect.ClearColor = Color.FromArgb(0x01, 0xFF, 0xFF, 0xFF); ClearIntensityMap(); Size sz = new Size(intensityMap.PixelWidth, intensityMap.PixelHeight); // Create the clear rectangle, we need this to render a fade pass. clearRectangle = new Rectangle(); clearRectangle.Fill = new ImageBrush(intensityMap); clearRectangle.Effect = cleareffect; clearRectangle.Measure(sz); clearRectangle.Arrange(new Rect(sz)); // Connect the intensity map containing our heat to our image. HeatMapImage.Source = intensityMap; }
private static BitmapSource CreateElementScreenshot(UIElement uiElement) { bool measureValid = uiElement.IsMeasureValid; if (!measureValid) { double width = 300; double height = 300; FrameworkElement frElement = uiElement as FrameworkElement; if (frElement != null) { if (!Double.IsNaN(frElement.Width)) width = frElement.Width; if (!Double.IsNaN(frElement.Height)) height = frElement.Height; } Size size = new Size(width, height); uiElement.Measure(size); uiElement.Arrange(new Rect(size)); } RenderTargetBitmap bmp = new RenderTargetBitmap( (int)uiElement.RenderSize.Width, (int)uiElement.RenderSize.Height, 96, 96, PixelFormats.Default); // this is waiting for dispatcher to perform measure, arrange and render passes uiElement.Dispatcher.Invoke(((Action)(() => { })), DispatcherPriority.Background); Size elementSize = uiElement.DesiredSize; // white background Rectangle whiteRect = new Rectangle { Width = elementSize.Width, Height = elementSize.Height, Fill = Brushes.White }; whiteRect.Measure(elementSize); whiteRect.Arrange(new Rect(elementSize)); bmp.Render(whiteRect); bmp.Render(uiElement); return bmp; }
public SquaredArrow() { Rectangle r = new Rectangle(); r.Measure(new Size(100, 100)); r.Arrange(new Rect(0, 0, 100, 100)); }