diff --git a/samples/ControlCatalog/MainView.xaml b/samples/ControlCatalog/MainView.xaml
index 874560a294..cbe2c62890 100644
--- a/samples/ControlCatalog/MainView.xaml
+++ b/samples/ControlCatalog/MainView.xaml
@@ -32,7 +32,11 @@
-
+
+
+
diff --git a/samples/ControlCatalog/Pages/ImagePage.xaml b/samples/ControlCatalog/Pages/ImagePage.xaml
index b44fac27cb..9b8f8af765 100644
--- a/samples/ControlCatalog/Pages/ImagePage.xaml
+++ b/samples/ControlCatalog/Pages/ImagePage.xaml
@@ -1,45 +1,52 @@
-
- Image
- Displays an image
-
-
-
- No Stretch
-
-
-
-
- Fill
-
-
+
+
+ Image
+ Displays an image
+
-
- Uniform
-
-
+
+
+
+ Bitmap
+
+ None
+ Fill
+ Uniform
+ UniformToFill
+
+
+
-
- UniformToFill
-
-
-
-
- Window Icon as an Image
-
-
-
+
+ Drawing
+
+ None
+ Fill
+ Uniform
+ UniformToFill
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/samples/ControlCatalog/Pages/ImagePage.xaml.cs b/samples/ControlCatalog/Pages/ImagePage.xaml.cs
index 792b25963e..bbe89d1dfd 100644
--- a/samples/ControlCatalog/Pages/ImagePage.xaml.cs
+++ b/samples/ControlCatalog/Pages/ImagePage.xaml.cs
@@ -1,40 +1,41 @@
-using System.IO;
-using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
-using Avalonia.Media.Imaging;
+using Avalonia.Media;
namespace ControlCatalog.Pages
{
public class ImagePage : UserControl
{
- private Image iconImage;
+ private readonly Image _bitmapImage;
+ private readonly Image _drawingImage;
+
public ImagePage()
{
- this.InitializeComponent();
+ InitializeComponent();
+ _bitmapImage = this.FindControl("bitmapImage");
+ _drawingImage = this.FindControl("drawingImage");
}
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
- iconImage = this.Get("Icon");
}
- protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
+ public void BitmapStretchChanged(object sender, SelectionChangedEventArgs e)
+ {
+ if (_bitmapImage != null)
+ {
+ var comboxBox = (ComboBox)sender;
+ _bitmapImage.Stretch = (Stretch)comboxBox.SelectedIndex;
+ }
+ }
+
+ public void DrawingStretchChanged(object sender, SelectionChangedEventArgs e)
{
- base.OnAttachedToVisualTree(e);
- if (iconImage.Source == null)
+ if (_drawingImage != null)
{
- var windowRoot = e.Root as Window;
- if (windowRoot != null)
- {
- using (var stream = new MemoryStream())
- {
- windowRoot.Icon.Save(stream);
- stream.Seek(0, SeekOrigin.Begin);
- iconImage.Source = new Bitmap(stream);
- }
- }
+ var comboxBox = (ComboBox)sender;
+ _drawingImage.Stretch = (Stretch)comboxBox.SelectedIndex;
}
}
}
diff --git a/samples/RenderDemo/Pages/RenderTargetBitmapPage.cs b/samples/RenderDemo/Pages/RenderTargetBitmapPage.cs
index 3eb2276c48..f263786ab7 100644
--- a/samples/RenderDemo/Pages/RenderTargetBitmapPage.cs
+++ b/samples/RenderDemo/Pages/RenderTargetBitmapPage.cs
@@ -39,7 +39,7 @@ namespace RenderDemo.Pages
ctx.FillRectangle(Brushes.Fuchsia, new Rect(50, 50, 100, 100));
}
- context.DrawImage(_bitmap, 1,
+ context.DrawImage(_bitmap,
new Rect(0, 0, 200, 200),
new Rect(0, 0, 200, 200));
Dispatcher.UIThread.Post(InvalidateVisual, DispatcherPriority.Background);
diff --git a/src/Avalonia.Controls/DrawingPresenter.cs b/src/Avalonia.Controls/DrawingPresenter.cs
index b30a8668fd..ee27aa7ec1 100644
--- a/src/Avalonia.Controls/DrawingPresenter.cs
+++ b/src/Avalonia.Controls/DrawingPresenter.cs
@@ -1,9 +1,11 @@
-using Avalonia.Controls.Shapes;
+using System;
+using Avalonia.Controls.Shapes;
using Avalonia.Media;
using Avalonia.Metadata;
namespace Avalonia.Controls
{
+ [Obsolete("Use Image control with DrawingImage source")]
public class DrawingPresenter : Control
{
static DrawingPresenter()
diff --git a/src/Avalonia.Controls/Image.cs b/src/Avalonia.Controls/Image.cs
index c2cdcb4e69..41b6e5449a 100644
--- a/src/Avalonia.Controls/Image.cs
+++ b/src/Avalonia.Controls/Image.cs
@@ -14,8 +14,8 @@ namespace Avalonia.Controls
///
/// Defines the property.
///
- public static readonly StyledProperty SourceProperty =
- AvaloniaProperty.Register(nameof(Source));
+ public static readonly StyledProperty SourceProperty =
+ AvaloniaProperty.Register(nameof(Source));
///
/// Defines the property.
@@ -38,9 +38,9 @@ namespace Avalonia.Controls
}
///
- /// Gets or sets the bitmap image that will be displayed.
+ /// Gets or sets the image that will be displayed.
///
- public IBitmap Source
+ public IImage Source
{
get { return GetValue(SourceProperty); }
set { SetValue(SourceProperty, value); }
@@ -75,7 +75,7 @@ namespace Avalonia.Controls
if (source != null)
{
Rect viewPort = new Rect(Bounds.Size);
- Size sourceSize = new Size(source.PixelSize.Width, source.PixelSize.Height);
+ Size sourceSize = source.Size;
Vector scale = Stretch.CalculateScaling(Bounds.Size, sourceSize, StretchDirection);
Size scaledSize = sourceSize * scale;
Rect destRect = viewPort
@@ -86,7 +86,7 @@ namespace Avalonia.Controls
var interpolationMode = RenderOptions.GetBitmapInterpolationMode(this);
- context.DrawImage(source, 1, sourceRect, destRect, interpolationMode);
+ context.DrawImage(source, sourceRect, destRect, interpolationMode);
}
}
@@ -102,8 +102,7 @@ namespace Avalonia.Controls
if (source != null)
{
- var sourceSize = new Size(source.PixelSize.Width, source.PixelSize.Height);
- result = Stretch.CalculateSize(availableSize, sourceSize, StretchDirection);
+ result = Stretch.CalculateSize(availableSize, source.Size, StretchDirection);
}
return result;
@@ -116,7 +115,7 @@ namespace Avalonia.Controls
if (source != null)
{
- var sourceSize = new Size(source.PixelSize.Width, source.PixelSize.Height);
+ var sourceSize = source.Size;
var result = Stretch.CalculateSize(finalSize, sourceSize);
return result;
}
diff --git a/src/Avalonia.Controls/Remote/RemoteWidget.cs b/src/Avalonia.Controls/Remote/RemoteWidget.cs
index 539fe1ec4b..c7a1a24c25 100644
--- a/src/Avalonia.Controls/Remote/RemoteWidget.cs
+++ b/src/Avalonia.Controls/Remote/RemoteWidget.cs
@@ -83,7 +83,7 @@ namespace Avalonia.Controls.Remote
Marshal.Copy(_lastFrame.Data, y * _lastFrame.Stride,
new IntPtr(l.Address.ToInt64() + l.RowBytes * y), lineLen);
}
- context.DrawImage(_bitmap, 1, new Rect(0, 0, _bitmap.PixelSize.Width, _bitmap.PixelSize.Height),
+ context.DrawImage(_bitmap, new Rect(0, 0, _bitmap.PixelSize.Width, _bitmap.PixelSize.Height),
new Rect(Bounds.Size));
}
base.Render(context);
diff --git a/src/Avalonia.Visuals/Media/Drawing.cs b/src/Avalonia.Visuals/Media/Drawing.cs
index a60c591edc..6bc808e407 100644
--- a/src/Avalonia.Visuals/Media/Drawing.cs
+++ b/src/Avalonia.Visuals/Media/Drawing.cs
@@ -1,4 +1,6 @@
-namespace Avalonia.Media
+using Avalonia.Platform;
+
+namespace Avalonia.Media
{
public abstract class Drawing : AvaloniaObject
{
@@ -6,4 +8,4 @@
public abstract Rect GetBounds();
}
-}
\ No newline at end of file
+}
diff --git a/src/Avalonia.Visuals/Media/DrawingContext.cs b/src/Avalonia.Visuals/Media/DrawingContext.cs
index df69ab6fd5..4045b92c0c 100644
--- a/src/Avalonia.Visuals/Media/DrawingContext.cs
+++ b/src/Avalonia.Visuals/Media/DrawingContext.cs
@@ -74,18 +74,29 @@ namespace Avalonia.Media
public Matrix CurrentContainerTransform => _currentContainerTransform;
///
- /// Draws a bitmap image.
+ /// Draws an image.
///
- /// The bitmap image.
- /// The opacity to draw with.
+ /// The image.
+ /// The rect in the output to draw to.
+ public void DrawImage(IImage source, Rect rect)
+ {
+ Contract.Requires(source != null);
+
+ DrawImage(source, new Rect(source.Size), rect);
+ }
+
+ ///
+ /// Draws an image.
+ ///
+ /// The image.
/// The rect in the image to draw.
/// The rect in the output to draw to.
/// The bitmap interpolation mode.
- public void DrawImage(IBitmap source, double opacity, Rect sourceRect, Rect destRect, BitmapInterpolationMode bitmapInterpolationMode = default)
+ public void DrawImage(IImage source, Rect sourceRect, Rect destRect, BitmapInterpolationMode bitmapInterpolationMode = default)
{
Contract.Requires(source != null);
- PlatformImpl.DrawImage(source.PlatformImpl, opacity, sourceRect, destRect, bitmapInterpolationMode);
+ source.Draw(this, sourceRect, destRect, bitmapInterpolationMode);
}
///
diff --git a/src/Avalonia.Visuals/Media/DrawingGroup.cs b/src/Avalonia.Visuals/Media/DrawingGroup.cs
index 744ff2af03..e581c8c553 100644
--- a/src/Avalonia.Visuals/Media/DrawingGroup.cs
+++ b/src/Avalonia.Visuals/Media/DrawingGroup.cs
@@ -1,5 +1,6 @@
using Avalonia.Collections;
using Avalonia.Metadata;
+using Avalonia.Platform;
namespace Avalonia.Media
{
@@ -55,4 +56,4 @@ namespace Avalonia.Media
return rect;
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Avalonia.Visuals/Media/DrawingImage.cs b/src/Avalonia.Visuals/Media/DrawingImage.cs
new file mode 100644
index 0000000000..d6ab004dd7
--- /dev/null
+++ b/src/Avalonia.Visuals/Media/DrawingImage.cs
@@ -0,0 +1,81 @@
+using System;
+using Avalonia.Metadata;
+using Avalonia.Platform;
+using Avalonia.Visuals.Media.Imaging;
+
+namespace Avalonia.Media
+{
+ ///
+ /// An that uses a for content.
+ ///
+ public class DrawingImage : AvaloniaObject, IImage, IAffectsRender
+ {
+ ///
+ /// Defines the property.
+ ///
+ public static readonly StyledProperty DrawingProperty =
+ AvaloniaProperty.Register(nameof(Drawing));
+
+ ///
+ public event EventHandler Invalidated;
+
+ ///
+ /// Gets or sets the drawing content.
+ ///
+ [Content]
+ public Drawing Drawing
+ {
+ get => GetValue(DrawingProperty);
+ set => SetValue(DrawingProperty, value);
+ }
+
+ ///
+ public Size Size => Drawing?.GetBounds().Size ?? default;
+
+ ///
+ void IImage.Draw(
+ DrawingContext context,
+ Rect sourceRect,
+ Rect destRect,
+ BitmapInterpolationMode bitmapInterpolationMode)
+ {
+ var drawing = Drawing;
+
+ if (drawing == null)
+ {
+ return;
+ }
+
+ var bounds = drawing.GetBounds();
+ var scale = Matrix.CreateScale(
+ destRect.Width / sourceRect.Width,
+ destRect.Height / sourceRect.Height);
+ var translate = Matrix.CreateTranslation(
+ -sourceRect.X + destRect.X - bounds.X,
+ -sourceRect.Y + destRect.Y - bounds.Y);
+
+ using (context.PushClip(destRect))
+ using (context.PushPreTransform(translate * scale))
+ {
+ Drawing?.Draw(context);
+ }
+ }
+
+ ///
+ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs e)
+ {
+ base.OnPropertyChanged(e);
+
+ if (e.Property == DrawingProperty)
+ {
+ RaiseInvalidated(EventArgs.Empty);
+ }
+ }
+
+ ///
+ /// Raises the event.
+ ///
+ /// The event args.
+ protected void RaiseInvalidated(EventArgs e) => Invalidated?.Invoke(this, e);
+ }
+}
diff --git a/src/Avalonia.Visuals/Media/GeometryDrawing.cs b/src/Avalonia.Visuals/Media/GeometryDrawing.cs
index 3dad10fb8f..4df3aa8ae2 100644
--- a/src/Avalonia.Visuals/Media/GeometryDrawing.cs
+++ b/src/Avalonia.Visuals/Media/GeometryDrawing.cs
@@ -1,10 +1,13 @@
-namespace Avalonia.Media
+using Avalonia.Metadata;
+
+namespace Avalonia.Media
{
public class GeometryDrawing : Drawing
{
public static readonly StyledProperty GeometryProperty =
AvaloniaProperty.Register(nameof(Geometry));
+ [Content]
public Geometry Geometry
{
get => GetValue(GeometryProperty);
diff --git a/src/Avalonia.Visuals/Media/IImage.cs b/src/Avalonia.Visuals/Media/IImage.cs
new file mode 100644
index 0000000000..aff2a9ddf9
--- /dev/null
+++ b/src/Avalonia.Visuals/Media/IImage.cs
@@ -0,0 +1,29 @@
+using Avalonia.Platform;
+using Avalonia.Visuals.Media.Imaging;
+
+namespace Avalonia.Media
+{
+ ///
+ /// Represents a raster or vector image.
+ ///
+ public interface IImage
+ {
+ ///
+ /// Gets the size of the image, in device independent pixels.
+ ///
+ Size Size { get; }
+
+ ///
+ /// Draws the image to a .
+ ///
+ /// The drawing context.
+ /// The rect in the image to draw.
+ /// The rect in the output to draw to.
+ /// The bitmap interpolation mode.
+ void Draw(
+ DrawingContext context,
+ Rect sourceRect,
+ Rect destRect,
+ BitmapInterpolationMode bitmapInterpolationMode);
+ }
+}
diff --git a/src/Avalonia.Visuals/Media/Imaging/Bitmap.cs b/src/Avalonia.Visuals/Media/Imaging/Bitmap.cs
index 8dd75d2374..14ac4261dc 100644
--- a/src/Avalonia.Visuals/Media/Imaging/Bitmap.cs
+++ b/src/Avalonia.Visuals/Media/Imaging/Bitmap.cs
@@ -5,6 +5,7 @@ using System;
using System.IO;
using Avalonia.Platform;
using Avalonia.Utilities;
+using Avalonia.Visuals.Media.Imaging;
namespace Avalonia.Media.Imaging
{
@@ -94,9 +95,28 @@ namespace Avalonia.Media.Imaging
PlatformImpl.Item.Save(fileName);
}
+ ///
+ /// Saves the bitmap to a stream.
+ ///
+ /// The stream.
public void Save(Stream stream)
{
PlatformImpl.Item.Save(stream);
}
+
+ ///
+ void IImage.Draw(
+ DrawingContext context,
+ Rect sourceRect,
+ Rect destRect,
+ BitmapInterpolationMode bitmapInterpolationMode)
+ {
+ context.PlatformImpl.DrawBitmap(
+ PlatformImpl,
+ 1,
+ sourceRect,
+ destRect,
+ bitmapInterpolationMode);
+ }
}
}
diff --git a/src/Avalonia.Visuals/Media/Imaging/IBitmap.cs b/src/Avalonia.Visuals/Media/Imaging/IBitmap.cs
index 90b13088e1..4c3203a95b 100644
--- a/src/Avalonia.Visuals/Media/Imaging/IBitmap.cs
+++ b/src/Avalonia.Visuals/Media/Imaging/IBitmap.cs
@@ -11,7 +11,7 @@ namespace Avalonia.Media.Imaging
///
/// Represents a bitmap image.
///
- public interface IBitmap : IDisposable
+ public interface IBitmap : IImage, IDisposable
{
///
/// Gets the dots per inch (DPI) of the image.
@@ -32,15 +32,6 @@ namespace Avalonia.Media.Imaging
///
IRef PlatformImpl { get; }
- ///
- /// Gets the size of the image, in device independent pixels.
- ///
- ///
- /// Note that Skia does not currently support reading the DPI of an image so this value
- /// will equal on Skia.
- ///
- Size Size { get; }
-
///
/// Saves the bitmap to a file.
///
diff --git a/src/Avalonia.Visuals/Platform/IDrawingContextImpl.cs b/src/Avalonia.Visuals/Platform/IDrawingContextImpl.cs
index f2309c271d..7d142b0759 100644
--- a/src/Avalonia.Visuals/Platform/IDrawingContextImpl.cs
+++ b/src/Avalonia.Visuals/Platform/IDrawingContextImpl.cs
@@ -33,7 +33,7 @@ namespace Avalonia.Platform
/// The rect in the image to draw.
/// The rect in the output to draw to.
/// The bitmap interpolation mode.
- void DrawImage(IRef source, double opacity, Rect sourceRect, Rect destRect, BitmapInterpolationMode bitmapInterpolationMode = BitmapInterpolationMode.Default);
+ void DrawBitmap(IRef source, double opacity, Rect sourceRect, Rect destRect, BitmapInterpolationMode bitmapInterpolationMode = BitmapInterpolationMode.Default);
///
/// Draws a bitmap image.
@@ -42,7 +42,7 @@ namespace Avalonia.Platform
/// The opacity mask to draw with.
/// The destination rect for the opacity mask.
/// The rect in the output to draw to.
- void DrawImage(IRef source, IBrush opacityMask, Rect opacityMaskRect, Rect destRect);
+ void DrawBitmap(IRef source, IBrush opacityMask, Rect opacityMaskRect, Rect destRect);
///
/// Draws a line.
diff --git a/src/Avalonia.Visuals/Rendering/DeferredRenderer.cs b/src/Avalonia.Visuals/Rendering/DeferredRenderer.cs
index 2fa249f101..585b132bd3 100644
--- a/src/Avalonia.Visuals/Rendering/DeferredRenderer.cs
+++ b/src/Avalonia.Visuals/Rendering/DeferredRenderer.cs
@@ -469,11 +469,11 @@ namespace Avalonia.Rendering
if (layer.OpacityMask == null)
{
- context.DrawImage(bitmap, layer.Opacity, sourceRect, clientRect);
+ context.DrawBitmap(bitmap, layer.Opacity, sourceRect, clientRect);
}
else
{
- context.DrawImage(bitmap, layer.OpacityMask, layer.OpacityMaskRect, sourceRect);
+ context.DrawBitmap(bitmap, layer.OpacityMask, layer.OpacityMaskRect, sourceRect);
}
if (layer.GeometryClip != null)
@@ -485,7 +485,7 @@ namespace Avalonia.Rendering
if (_overlay != null)
{
var sourceRect = new Rect(0, 0, _overlay.Item.PixelSize.Width, _overlay.Item.PixelSize.Height);
- context.DrawImage(_overlay, 0.5, sourceRect, clientRect);
+ context.DrawBitmap(_overlay, 0.5, sourceRect, clientRect);
}
if (DrawFps)
diff --git a/src/Avalonia.Visuals/Rendering/SceneGraph/DeferredDrawingContextImpl.cs b/src/Avalonia.Visuals/Rendering/SceneGraph/DeferredDrawingContextImpl.cs
index a169a629be..b362321745 100644
--- a/src/Avalonia.Visuals/Rendering/SceneGraph/DeferredDrawingContextImpl.cs
+++ b/src/Avalonia.Visuals/Rendering/SceneGraph/DeferredDrawingContextImpl.cs
@@ -115,7 +115,7 @@ namespace Avalonia.Rendering.SceneGraph
}
///
- public void DrawImage(IRef source, double opacity, Rect sourceRect, Rect destRect, BitmapInterpolationMode bitmapInterpolationMode)
+ public void DrawBitmap(IRef source, double opacity, Rect sourceRect, Rect destRect, BitmapInterpolationMode bitmapInterpolationMode)
{
var next = NextDrawAs();
@@ -130,7 +130,7 @@ namespace Avalonia.Rendering.SceneGraph
}
///
- public void DrawImage(IRef source, IBrush opacityMask, Rect opacityMaskRect, Rect sourceRect)
+ public void DrawBitmap(IRef source, IBrush opacityMask, Rect opacityMaskRect, Rect sourceRect)
{
// This method is currently only used to composite layers so shouldn't be called here.
throw new NotSupportedException();
diff --git a/src/Avalonia.Visuals/Rendering/SceneGraph/ImageNode.cs b/src/Avalonia.Visuals/Rendering/SceneGraph/ImageNode.cs
index e1bdcaab3b..054f33c95d 100644
--- a/src/Avalonia.Visuals/Rendering/SceneGraph/ImageNode.cs
+++ b/src/Avalonia.Visuals/Rendering/SceneGraph/ImageNode.cs
@@ -100,7 +100,7 @@ namespace Avalonia.Rendering.SceneGraph
public override void Render(IDrawingContextImpl context)
{
context.Transform = Transform;
- context.DrawImage(Source, Opacity, SourceRect, DestRect, BitmapInterpolationMode);
+ context.DrawBitmap(Source, Opacity, SourceRect, DestRect, BitmapInterpolationMode);
}
///
diff --git a/src/Avalonia.X11/X11IconLoader.cs b/src/Avalonia.X11/X11IconLoader.cs
index f0e75536d0..093f2b12c1 100644
--- a/src/Avalonia.X11/X11IconLoader.cs
+++ b/src/Avalonia.X11/X11IconLoader.cs
@@ -59,7 +59,7 @@ namespace Avalonia.X11
}
using(var rt = AvaloniaLocator.Current.GetService().CreateRenderTarget(new[]{this}))
using (var ctx = rt.CreateDrawingContext(null))
- ctx.DrawImage(bitmap.PlatformImpl, 1, new Rect(bitmap.Size),
+ ctx.DrawBitmap(bitmap.PlatformImpl, 1, new Rect(bitmap.Size),
new Rect(0, 0, _width, _height));
Data = new UIntPtr[_width * _height + 2];
Data[0] = new UIntPtr((uint)_width);
diff --git a/src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/AvaloniaXamlIlLanguage.cs b/src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/AvaloniaXamlIlLanguage.cs
index 63c8b1c074..ebe4035ed6 100644
--- a/src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/AvaloniaXamlIlLanguage.cs
+++ b/src/Markup/Avalonia.Markup.Xaml/XamlIl/CompilerExtensions/AvaloniaXamlIlLanguage.cs
@@ -99,7 +99,7 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions
void Add(string type, string conv)
=> AddType(typeSystem.GetType(type), typeSystem.GetType(conv));
- Add("Avalonia.Media.Imaging.IBitmap","Avalonia.Markup.Xaml.Converters.BitmapTypeConverter");
+ Add("Avalonia.Media.IImage","Avalonia.Markup.Xaml.Converters.BitmapTypeConverter");
var ilist = typeSystem.GetType("System.Collections.Generic.IList`1");
AddType(ilist.MakeGenericType(typeSystem.GetType("Avalonia.Point")),
typeSystem.GetType("Avalonia.Markup.Xaml.Converters.PointsListTypeConverter"));
diff --git a/src/Skia/Avalonia.Skia/DrawingContextImpl.cs b/src/Skia/Avalonia.Skia/DrawingContextImpl.cs
index d06cfa69a7..1c05f8ac9f 100644
--- a/src/Skia/Avalonia.Skia/DrawingContextImpl.cs
+++ b/src/Skia/Avalonia.Skia/DrawingContextImpl.cs
@@ -110,7 +110,7 @@ namespace Avalonia.Skia
}
///
- public void DrawImage(IRef source, double opacity, Rect sourceRect, Rect destRect, BitmapInterpolationMode bitmapInterpolationMode)
+ public void DrawBitmap(IRef source, double opacity, Rect sourceRect, Rect destRect, BitmapInterpolationMode bitmapInterpolationMode)
{
var drawableImage = (IDrawableBitmapImpl)source.Item;
var s = sourceRect.ToSKRect();
@@ -146,10 +146,10 @@ namespace Avalonia.Skia
}
///
- public void DrawImage(IRef source, IBrush opacityMask, Rect opacityMaskRect, Rect destRect)
+ public void DrawBitmap(IRef source, IBrush opacityMask, Rect opacityMaskRect, Rect destRect)
{
PushOpacityMask(opacityMask, opacityMaskRect);
- DrawImage(source, 1, new Rect(0, 0, source.Item.PixelSize.Width, source.Item.PixelSize.Height), destRect, BitmapInterpolationMode.Default);
+ DrawBitmap(source, 1, new Rect(0, 0, source.Item.PixelSize.Width, source.Item.PixelSize.Height), destRect, BitmapInterpolationMode.Default);
PopOpacityMask();
}
@@ -437,7 +437,7 @@ namespace Avalonia.Skia
context.Clear(Colors.Transparent);
context.PushClip(calc.IntermediateClip);
context.Transform = calc.IntermediateTransform;
- context.DrawImage(
+ context.DrawBitmap(
RefCountable.CreateUnownedNotClonable(tileBrushImage),
1,
sourceRect,
diff --git a/src/Windows/Avalonia.Direct2D1/Media/DrawingContextImpl.cs b/src/Windows/Avalonia.Direct2D1/Media/DrawingContextImpl.cs
index aa13003643..81d869f3b8 100644
--- a/src/Windows/Avalonia.Direct2D1/Media/DrawingContextImpl.cs
+++ b/src/Windows/Avalonia.Direct2D1/Media/DrawingContextImpl.cs
@@ -109,7 +109,7 @@ namespace Avalonia.Direct2D1.Media
/// The rect in the image to draw.
/// The rect in the output to draw to.
/// The bitmap interpolation mode.
- public void DrawImage(IRef source, double opacity, Rect sourceRect, Rect destRect, BitmapInterpolationMode bitmapInterpolationMode)
+ public void DrawBitmap(IRef source, double opacity, Rect sourceRect, Rect destRect, BitmapInterpolationMode bitmapInterpolationMode)
{
using (var d2d = ((BitmapImpl)source.Item).GetDirect2DBitmap(_deviceContext))
{
@@ -149,7 +149,7 @@ namespace Avalonia.Direct2D1.Media
/// The opacity mask to draw with.
/// The destination rect for the opacity mask.
/// The rect in the output to draw to.
- public void DrawImage(IRef source, IBrush opacityMask, Rect opacityMaskRect, Rect destRect)
+ public void DrawBitmap(IRef source, IBrush opacityMask, Rect opacityMaskRect, Rect destRect)
{
using (var d2dSource = ((BitmapImpl)source.Item).GetDirect2DBitmap(_deviceContext))
using (var sourceBrush = new BitmapBrush(_deviceContext, d2dSource.Value))
diff --git a/src/Windows/Avalonia.Direct2D1/Media/ImageBrushImpl.cs b/src/Windows/Avalonia.Direct2D1/Media/ImageBrushImpl.cs
index fbc6d21cb7..6632e2b3e7 100644
--- a/src/Windows/Avalonia.Direct2D1/Media/ImageBrushImpl.cs
+++ b/src/Windows/Avalonia.Direct2D1/Media/ImageBrushImpl.cs
@@ -107,7 +107,7 @@ namespace Avalonia.Direct2D1.Media
context.PushClip(calc.IntermediateClip);
context.Transform = calc.IntermediateTransform;
- context.DrawImage(RefCountable.CreateUnownedNotClonable(bitmap), 1, rect, rect, _bitmapInterpolationMode);
+ context.DrawBitmap(RefCountable.CreateUnownedNotClonable(bitmap), 1, rect, rect, _bitmapInterpolationMode);
context.PopClip();
}
diff --git a/src/Windows/Avalonia.Direct2D1/Media/Imaging/D2DBitmapImpl.cs b/src/Windows/Avalonia.Direct2D1/Media/Imaging/D2DBitmapImpl.cs
index 1ee869ecb9..29c9280af6 100644
--- a/src/Windows/Avalonia.Direct2D1/Media/Imaging/D2DBitmapImpl.cs
+++ b/src/Windows/Avalonia.Direct2D1/Media/Imaging/D2DBitmapImpl.cs
@@ -30,7 +30,7 @@ namespace Avalonia.Direct2D1.Media
_direct2DBitmap = d2DBitmap ?? throw new ArgumentNullException(nameof(d2DBitmap));
}
- public override Vector Dpi => _direct2DBitmap.DotsPerInch.ToAvaloniaVector();
+ public override Vector Dpi => new Vector(96, 96);
public override PixelSize PixelSize => _direct2DBitmap.PixelSize.ToAvalonia();
public override void Dispose()
@@ -58,3 +58,4 @@ namespace Avalonia.Direct2D1.Media
}
}
}
+;
diff --git a/src/Windows/Avalonia.Direct2D1/Media/Imaging/D2DRenderTargetBitmapImpl.cs b/src/Windows/Avalonia.Direct2D1/Media/Imaging/D2DRenderTargetBitmapImpl.cs
index 8ec368c999..b96441e357 100644
--- a/src/Windows/Avalonia.Direct2D1/Media/Imaging/D2DRenderTargetBitmapImpl.cs
+++ b/src/Windows/Avalonia.Direct2D1/Media/Imaging/D2DRenderTargetBitmapImpl.cs
@@ -58,7 +58,7 @@ namespace Avalonia.Direct2D1.Media.Imaging
{
using (var dc = wic.CreateDrawingContext(null))
{
- dc.DrawImage(
+ dc.DrawBitmap(
RefCountable.CreateUnownedNotClonable(this),
1,
new Rect(PixelSize.ToSizeWithDpi(Dpi.X)),
diff --git a/src/Windows/Avalonia.Direct2D1/Media/Imaging/WicBitmapImpl.cs b/src/Windows/Avalonia.Direct2D1/Media/Imaging/WicBitmapImpl.cs
index 176c3e0e23..4e0853c20c 100644
--- a/src/Windows/Avalonia.Direct2D1/Media/Imaging/WicBitmapImpl.cs
+++ b/src/Windows/Avalonia.Direct2D1/Media/Imaging/WicBitmapImpl.cs
@@ -26,6 +26,7 @@ namespace Avalonia.Direct2D1.Media
using (BitmapDecoder decoder = new BitmapDecoder(Direct2D1Platform.ImagingFactory, fileName, DecodeOptions.CacheOnDemand))
{
WicImpl = new Bitmap(Direct2D1Platform.ImagingFactory, decoder.GetFrame(0), BitmapCreateCacheOption.CacheOnDemand);
+ Dpi = new Vector(96, 96);
}
}
@@ -39,6 +40,7 @@ namespace Avalonia.Direct2D1.Media
_decoder = new BitmapDecoder(Direct2D1Platform.ImagingFactory, stream, DecodeOptions.CacheOnLoad);
WicImpl = new Bitmap(Direct2D1Platform.ImagingFactory, _decoder.GetFrame(0), BitmapCreateCacheOption.CacheOnLoad);
+ Dpi = new Vector(96, 96);
}
///
@@ -62,6 +64,7 @@ namespace Avalonia.Direct2D1.Media
pixelFormat.Value.ToWic(),
BitmapCreateCacheOption.CacheOnLoad);
WicImpl.SetResolution(dpi.X, dpi.Y);
+ Dpi = dpi;
}
public WicBitmapImpl(APixelFormat format, IntPtr data, PixelSize size, Vector dpi, int stride)
@@ -70,6 +73,8 @@ namespace Avalonia.Direct2D1.Media
WicImpl.SetResolution(dpi.X, dpi.Y);
PixelFormat = format;
+ Dpi = dpi;
+
using (var l = WicImpl.Lock(BitmapLockFlags.Write))
{
for (var row = 0; row < size.Height; row++)
@@ -82,14 +87,7 @@ namespace Avalonia.Direct2D1.Media
}
}
- public override Vector Dpi
- {
- get
- {
- WicImpl.GetResolution(out double x, out double y);
- return new Vector(x, y);
- }
- }
+ public override Vector Dpi { get; }
public override PixelSize PixelSize => WicImpl.Size.ToAvalonia();
diff --git a/tests/Avalonia.Controls.UnitTests/ImageTests.cs b/tests/Avalonia.Controls.UnitTests/ImageTests.cs
index 5102085fbf..d3c0e29eca 100644
--- a/tests/Avalonia.Controls.UnitTests/ImageTests.cs
+++ b/tests/Avalonia.Controls.UnitTests/ImageTests.cs
@@ -169,7 +169,7 @@ namespace Avalonia.Controls.UnitTests
private IBitmap CreateBitmap(int width, int height)
{
- return Mock.Of(x => x.PixelSize == new PixelSize(width, height));
+ return Mock.Of(x => x.Size == new Size(width, height));
}
}
}
diff --git a/tests/Avalonia.RenderTests/Media/BitmapTests.cs b/tests/Avalonia.RenderTests/Media/BitmapTests.cs
index 97e234a55b..7564d43070 100644
--- a/tests/Avalonia.RenderTests/Media/BitmapTests.cs
+++ b/tests/Avalonia.RenderTests/Media/BitmapTests.cs
@@ -94,7 +94,7 @@ namespace Avalonia.Direct2D1.RenderTests.Media
ctx.DrawRectangle(Brushes.Pink, null, new Rect(0, 20, 100, 10));
var rc = new Rect(0, 0, 60, 60);
- ctx.DrawImage(bmp.PlatformImpl, 1, rc, rc);
+ ctx.DrawBitmap(bmp.PlatformImpl, 1, rc, rc);
}
rtb.Save(System.IO.Path.Combine(OutputPath, testName + ".out.png"));
}
diff --git a/tests/Avalonia.Visuals.UnitTests/Rendering/DeferredRendererTests.cs b/tests/Avalonia.Visuals.UnitTests/Rendering/DeferredRendererTests.cs
index 2061caa320..ea192a1310 100644
--- a/tests/Avalonia.Visuals.UnitTests/Rendering/DeferredRendererTests.cs
+++ b/tests/Avalonia.Visuals.UnitTests/Rendering/DeferredRendererTests.cs
@@ -670,7 +670,7 @@ namespace Avalonia.Visuals.UnitTests.Rendering
var context = Mock.Get(target.RenderTarget.CreateDrawingContext(null));
var borderLayer = target.Layers[border].Bitmap;
- context.Verify(x => x.DrawImage(borderLayer, 0.5, It.IsAny(), It.IsAny(), BitmapInterpolationMode.Default));
+ context.Verify(x => x.DrawBitmap(borderLayer, 0.5, It.IsAny(), It.IsAny(), BitmapInterpolationMode.Default));
}
[Fact]