Use Render Target Bitmap
<Window x:Class="BitmapProgramming.UseRenderTargetBitmap"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="BitmapProgramming" Height="300" Width="300">
<Image x:Name="imageElement" />
</Window>
//File:Window.xaml.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace BitmapProgramming
{
public partial class UseRenderTargetBitmap : System.Windows.Window
{
public UseRenderTargetBitmap()
{
InitializeComponent();
RenderTargetBitmap bmp = new RenderTargetBitmap(
300, 150, // Dimensions in physical pixels
300, 300, // Pixel resolution (dpi)
PixelFormats.Pbgra32);
Ellipse e = new Ellipse();
e.Fill = Brushes.Red;
e.Measure(new Size(96, 48));
e.Arrange(new Rect(0, 0, 96, 48));
bmp.Render(e);
imageElement.Source = bmp;
}
}
}
Related examples in the same category