in ExampleGallery/CustomEffects.xaml.cs [135:206]
void Canvas_Draw(ICanvasAnimatedControl sender, CanvasAnimatedDrawEventArgs args)
{
var elapsedTime = (float)args.Timing.TotalTime.TotalSeconds;
// Center in the control.
var position = (sender.Size.ToVector2() - tigerSize) / 2;
position.Y -= tigerSize.Y * 0.75f;
// Is the sketch effect enabled?
ICanvasImage sourceImage;
if (SketchEnabled)
sourceImage = sketchEffect;
else
sourceImage = bitmapTiger;
// Which dissolve mode are we currently displaying?
ICanvasImage dissolveMask;
switch (CurrentDissolve)
{
case DissolveType.Ripples:
// Use the custom rippleEffect as our dissolve mask, and animate its offset.
dissolveMask = rippleEffect;
rippleEffect.Properties["offset"] = -elapsedTime * 6;
break;
case DissolveType.Turbulence:
// Use a turbulence image as the dissolve mask.
dissolveMask = turbulence;
break;
case DissolveType.LinearGradient:
// Use a linear gradient as the dissolve mask, and slowly rotate it.
dissolveMask = linearGradient;
linearGradient.TransformMatrix = Matrix3x2.CreateRotation(elapsedTime / 3, tigerSize / 2);
break;
case DissolveType.RadialGradient:
// Use a radial gradient as the dissolve mask.
dissolveMask = radialGradient;
break;
case DissolveType.NoDissolve:
// Dissolve is turned off, so just draw the source image directly.
args.DrawingSession.DrawImage(sourceImage, position);
return;
default:
throw new NotSupportedException();
}
// Animate the dissolve amount.
dissolveEffect.Properties["dissolveAmount"] = (float)Math.Sin(elapsedTime * 2.4) / 2 + 0.5f;
// Draw the custom effect.
dissolveEffect.Source1 = sourceImage;
dissolveEffect.Source2 = dissolveMask;
args.DrawingSession.DrawImage(dissolveEffect, position);
if (!ThumbnailGenerator.IsDrawingThumbnail)
{
// Display the current dissolve mask.
args.DrawingSession.DrawText("Dissolve mask:", position.X, position.Y + tigerSize.Y * 1.5f - 32, Colors.Gray);
args.DrawingSession.DrawImage(dissolveMask, position.X, position.Y + tigerSize.Y * 1.5f, bitmapTiger.Bounds);
// Display the current dissolve amount.
string dissolvePercentage = string.Format("{0:0}%", (float)dissolveEffect.Properties["dissolveAmount"] * 100);
args.DrawingSession.DrawText(dissolvePercentage, position + tigerSize * new Vector2(1.2f, 0.4f), Colors.Gray);
}
}