Here are a few possibilities:
- Create an image using overlapping linear gradient brushes.
- Create the image as a bitmap.
- Create an image during rendering using pixel shaders.
Overlapping gradient brushes
For the image that you showed, you can achieve the desired effect using something in this direction:
<Grid>
<Rectangle>
<Rectangle.Fill>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Offset="0" Color="#FFFF8040" />
<GradientStop Offset="1" Color="#FFFFFFFF" />
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<Rectangle>
<Rectangle.Fill>
<LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
<GradientStop Offset="0" Color="#FF000000" />
<GradientStop Offset="1" Color="#00000000" />
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
</Grid>
The first fill sets the color, and the second fill darkens it. Obviously, this can be done in Drawing or VisualBrush.
This is the simplest solution, but it is limited by what it can produce.
Creating a bitmap image
, . . , . , . , : TransformToDevice , WPF .
, :
uint[] pixels = new uint[width*height];
for(int x=0; x<width; x++)
for(int y=0; y<height; y++)
pixels[y*width + x] = ComputeColor(x, y);
var bitmap = new WritableBitmap(width, height, 96, 96, PixelFormat.Pbgra32, null);
bitmap.WritePixels(new Rect(0, 0, width, height), pixels, width*4, 0);
, . , . , # VB.NET: (HLSL), .
- :
WPF