Browse Source

Sanitize image drawing API.

- Remove opacity parameter - should push an opacity instead
- Add a WPF-compatible overload of `DrawImage` to `DrawingContext`
pull/3378/head
Steven Kirk 6 years ago
parent
commit
dbe4301d36
  1. 2
      samples/RenderDemo/Pages/RenderTargetBitmapPage.cs
  2. 2
      src/Avalonia.Controls/Image.cs
  3. 2
      src/Avalonia.Controls/Remote/RemoteWidget.cs
  4. 17
      src/Avalonia.Visuals/Media/DrawingContext.cs
  5. 1
      src/Avalonia.Visuals/Media/DrawingImage.cs
  6. 2
      src/Avalonia.Visuals/Media/IImage.cs
  7. 3
      src/Avalonia.Visuals/Media/Imaging/Bitmap.cs

2
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);

2
src/Avalonia.Controls/Image.cs

@ -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);
}
}

2
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);

17
src/Avalonia.Visuals/Media/DrawingContext.cs

@ -77,15 +77,26 @@ namespace Avalonia.Media
/// Draws an image.
/// </summary>
/// <param name="source">The image.</param>
/// <param name="opacity">The opacity to draw with.</param>
/// <param name="rect">The rect in the output to draw to.</param>
public void DrawImage(IImage source, Rect rect)
{
Contract.Requires<ArgumentNullException>(source != null);
DrawImage(source, new Rect(source.Size), rect);
}
/// <summary>
/// Draws an image.
/// </summary>
/// <param name="source">The image.</param>
/// <param name="sourceRect">The rect in the image to draw.</param>
/// <param name="destRect">The rect in the output to draw to.</param>
/// <param name="bitmapInterpolationMode">The bitmap interpolation mode.</param>
public void DrawImage(IImage source, double opacity, Rect sourceRect, Rect destRect, BitmapInterpolationMode bitmapInterpolationMode = default)
public void DrawImage(IImage source, Rect sourceRect, Rect destRect, BitmapInterpolationMode bitmapInterpolationMode = default)
{
Contract.Requires<ArgumentNullException>(source != null);
source.Draw(this, opacity, sourceRect, destRect, bitmapInterpolationMode);
source.Draw(this, sourceRect, destRect, bitmapInterpolationMode);
}
/// <summary>

1
src/Avalonia.Visuals/Media/DrawingImage.cs

@ -20,7 +20,6 @@ namespace Avalonia.Media
public void Draw(
DrawingContext context,
double opacity,
Rect sourceRect,
Rect destRect,
BitmapInterpolationMode bitmapInterpolationMode)

2
src/Avalonia.Visuals/Media/IImage.cs

@ -17,13 +17,11 @@ namespace Avalonia.Media
/// Draws the image to a <see cref="DrawingContext"/>.
/// </summary>
/// <param name="context">The drawing context.</param>
/// <param name="opacity">The opacity to draw with.</param>
/// <param name="sourceRect">The rect in the image to draw.</param>
/// <param name="destRect">The rect in the output to draw to.</param>
/// <param name="bitmapInterpolationMode">The bitmap interpolation mode.</param>
void Draw(
DrawingContext context,
double opacity,
Rect sourceRect,
Rect destRect,
BitmapInterpolationMode bitmapInterpolationMode);

3
src/Avalonia.Visuals/Media/Imaging/Bitmap.cs

@ -107,14 +107,13 @@ namespace Avalonia.Media.Imaging
/// <inheritdoc/>
void IImage.Draw(
DrawingContext context,
double opacity,
Rect sourceRect,
Rect destRect,
BitmapInterpolationMode bitmapInterpolationMode)
{
context.PlatformImpl.DrawBitmap(
PlatformImpl,
opacity,
1,
sourceRect,
destRect,
bitmapInterpolationMode);

Loading…
Cancel
Save