// Copyright (c) The Avalonia Project. All rights reserved. // Licensed under the MIT license. See licence.md file in the project root for full license information. using System; using Avalonia.Platform; using Avalonia.Rendering; using Avalonia.VisualTree; namespace Avalonia.Media.Imaging { /// /// A bitmap that holds the rendering of a . /// public class RenderTargetBitmap : Bitmap, IDisposable, IRenderTarget { /// /// Initializes a new instance of the class. /// /// The width of the bitmap. /// The height of the bitmap. public RenderTargetBitmap(int width, int height) : base(CreateImpl(width, height)) { } /// /// Gets the platform-specific bitmap implementation. /// public new IRenderTargetBitmapImpl PlatformImpl => (IRenderTargetBitmapImpl)base.PlatformImpl; /// /// Disposes of the bitmap. /// public void Dispose() { PlatformImpl.Dispose(); } /// /// Creates a platform-specific imlementation for a . /// /// The width of the bitmap. /// The height of the bitmap. /// The platform-specific implementation. private static IBitmapImpl CreateImpl(int width, int height) { IPlatformRenderInterface factory = AvaloniaLocator.Current.GetService(); return factory.CreateRenderTargetBitmap(width, height); } public DrawingContext CreateDrawingContext() => PlatformImpl.CreateDrawingContext(); } }