csharpc-sharpdotnetxamlavaloniauicross-platformcross-platform-xamlavaloniaguimulti-platformuser-interfacedotnetcore
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.5 KiB
46 lines
1.5 KiB
using System.Diagnostics;
|
|
using Avalonia;
|
|
using Avalonia.Controls;
|
|
using Avalonia.LogicalTree;
|
|
using Avalonia.Media;
|
|
using Avalonia.Media.Imaging;
|
|
using Avalonia.Threading;
|
|
|
|
namespace RenderDemo.Pages
|
|
{
|
|
public class RenderTargetBitmapPage : Control
|
|
{
|
|
private RenderTargetBitmap _bitmap;
|
|
|
|
protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
|
|
{
|
|
_bitmap = new RenderTargetBitmap(new PixelSize(200, 200), new Vector(96, 96));
|
|
base.OnAttachedToLogicalTree(e);
|
|
}
|
|
|
|
protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)
|
|
{
|
|
_bitmap.Dispose();
|
|
_bitmap = null;
|
|
base.OnDetachedFromLogicalTree(e);
|
|
}
|
|
|
|
readonly Stopwatch _st = Stopwatch.StartNew();
|
|
public override void Render(DrawingContext context)
|
|
{
|
|
using (var ctx = _bitmap.CreateDrawingContext())
|
|
using (ctx.PushTransform(Matrix.CreateTranslation(-100, -100)
|
|
* Matrix.CreateRotation(_st.Elapsed.TotalSeconds)
|
|
* Matrix.CreateTranslation(100, 100)))
|
|
{
|
|
ctx.FillRectangle(Brushes.Fuchsia, new Rect(50, 50, 100, 100));
|
|
}
|
|
|
|
context.DrawImage(_bitmap,
|
|
new Rect(0, 0, 200, 200),
|
|
new Rect(0, 0, 200, 200));
|
|
Dispatcher.UIThread.Post(InvalidateVisual, DispatcherPriority.Background);
|
|
base.Render(context);
|
|
}
|
|
}
|
|
}
|
|
|