Draw Graphics On Bitmap

   
 

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;

    public class DrawGraphicsOnBitmap : Window
    {
        [STAThread]
        public static void Main()
        {
            Application app = new Application();
            app.Run(new DrawGraphicsOnBitmap());
        }
        public DrawGraphicsOnBitmap()
        {
            Background = Brushes.Khaki;
            RenderTargetBitmap renderbitmap = new RenderTargetBitmap(100, 100, 96, 96, PixelFormats.Default);
            DrawingVisual drawvis = new DrawingVisual();
            DrawingContext dc = drawvis.RenderOpen();
            dc.DrawRoundedRectangle(Brushes.Blue, new Pen(Brushes.Red, 10),new Rect(25, 25, 50, 50), 10, 10);
            dc.Close();
            renderbitmap.Render(drawvis);
            Image img = new Image();
            img.Source = renderbitmap;

            Content = img;
        }
    }

   
     


Create Full Color Bitmap

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;

public class CreateFullColorBitmap : Window
{
[STAThread]
public static void Main()
{
Application app = new Application();
app.Run(new CreateFullColorBitmap());
}
public CreateFullColorBitmap()
{
int[] array = new int[256 * 256];

for (int x = 0; x < 256; x++) for (int y = 0; y < 256; y++) { int b = x; int g = 0; int r = y; array[256 * y + x] = b | (g << 8) | (r << 16); } BitmapSource bitmap= BitmapSource.Create(256, 256, 96, 96, PixelFormats.Bgr32, null, array, 256 * 4); Image img = new Image(); img.Source = bitmap; Content = img; } } [/csharp]

Shadow effect by creating an outer glow


   
 

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  x:Class="SDKSample.Window1" Title="Text Shadow Samples"
  Background="FloralWhite">
  <StackPanel>

      <TextBlock FontSize="64" Text="{Binding Path=Text, ElementName=textblockMaster}"
        Foreground="SteelBlue" Grid.Column="1" Grid.Row="4">
        <TextBlock.BitmapEffect>
          <OuterGlowBitmapEffect
            GlowSize="1.0"
            GlowColor="Orange"
            Opacity="1.0"/>
        </TextBlock.BitmapEffect>
      </TextBlock>

  </StackPanel>
</Window>

   
     


Hard shadow on top of noisy shadow


   
 


<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  x:Class="SDKSample.Window1" Title="Text Shadow Samples"
  Background="FloralWhite">
  <StackPanel>

      <TextBlock FontSize="64"
        Text="asdf"
        Foreground="Silver"
        Grid.Column="1" Grid.Row="3">
        <TextBlock.BitmapEffect>
          <BitmapEffectGroup>
            <DropShadowBitmapEffect
              ShadowDepth="3"
              Direction="330"
              Color="Black"
              Opacity="0.75"
              Softness="0.0" />
            <DropShadowBitmapEffect
              Noise="0.75"
              ShadowDepth="6"
              Direction="330"
              Color="Black"
              Opacity="0.35"
              Softness="0.25" />
          </BitmapEffectGroup>
        </TextBlock.BitmapEffect>
      </TextBlock>


  </StackPanel>
</Window>

   
     


Hard shadow on top of soft shadow


   
 


<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  x:Class="SDKSample.Window1" Title="Text Shadow Samples"
  Background="FloralWhite">
  <StackPanel>

      <TextBlock FontSize="64" Text="asdf" Foreground="Yellow">
        <TextBlock.BitmapEffect>
          <BitmapEffectGroup>
            <DropShadowBitmapEffect ShadowDepth="5" Direction="330" Color="Orange"
              Opacity="0.75"
              Softness="0.50" />
            <DropShadowBitmapEffect
              ShadowDepth="2"
              Direction="330"
              Color="Red"
              Opacity="0.5"
              Softness="0.0" />
          </BitmapEffectGroup>
        </TextBlock.BitmapEffect>
      </TextBlock>


  </StackPanel>
</Window>

   
     


Hard single shadow


   
 


<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  x:Class="SDKSample.Window1" Title="Text Shadow Samples"
  Background="FloralWhite">
  <StackPanel>
      <TextBlock
        FontSize="64"
        Text="asdf"
        Foreground="Maroon"
        Grid.Column="1" Grid.Row="1">
        <TextBlock.BitmapEffect>
          <DropShadowBitmapEffect
            ShadowDepth="6"
            Direction="135"
            Color="Maroon"
            Opacity="0.35"
            Softness="0.0" />
        </TextBlock.BitmapEffect>
      </TextBlock>


  </StackPanel>
</Window>

   
     


Create a shadow effect for displayed text.


   
 

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  x:Class="SDKSample.Window1" Title="Text Shadow Samples"
  Background="FloralWhite">
  <StackPanel>
      <TextBlock FontSize="64" Text="Shadow Text" Foreground="Teal">
        <TextBlock.BitmapEffect>
          <DropShadowBitmapEffect ShadowDepth="6" Direction="330" Color="Black" Opacity="0.5" Softness="0.25" />
        </TextBlock.BitmapEffect>
      </TextBlock>
  </StackPanel>
</Window>