Browse Source

Merge pull request #674 from nc4rrillo/img-rz

Use GDK to scale images instead of cairo
pull/676/head
Jeremy Koritzinsky 10 years ago
committed by GitHub
parent
commit
d892ac393e
  1. 53
      src/Gtk/Avalonia.Cairo/Media/DrawingContext.cs

53
src/Gtk/Avalonia.Cairo/Media/DrawingContext.cs

@ -77,40 +77,25 @@ namespace Avalonia.Cairo.Media
/// <param name="destRect">The rect in the output to draw to.</param> /// <param name="destRect">The rect in the output to draw to.</param>
public void DrawImage(IBitmap bitmap, double opacity, Rect sourceRect, Rect destRect) public void DrawImage(IBitmap bitmap, double opacity, Rect sourceRect, Rect destRect)
{ {
var impl = bitmap.PlatformImpl as BitmapImpl; var impl = bitmap.PlatformImpl as BitmapImpl;
var size = new Size(impl.PixelWidth, impl.PixelHeight); var size = new Size(impl.PixelWidth, impl.PixelHeight);
var scale = new Vector(destRect.Width / sourceRect.Width, destRect.Height / sourceRect.Height); var scale = new Vector(destRect.Width / sourceRect.Width, destRect.Height / sourceRect.Height);
_context.Save(); _context.Save();
_context.Scale(scale.X, scale.Y);
destRect /= scale; Gdk.CairoHelper.SetSourcePixbuf (
_context,
if (opacityOverride < 1.0f) { impl,
_context.PushGroup (); -sourceRect.X + destRect.X,
Gdk.CairoHelper.SetSourcePixbuf ( -sourceRect.Y + destRect.Y);
_context, impl.Scale (impl, (int)destRect.X, (int)destRect.Y, (int)destRect.Width, (int)destRect.Height, 0, 0, scale.X, scale.Y, Gdk.InterpType.Bilinear);
impl,
-sourceRect.X + destRect.X, _context.PushGroup ();
-sourceRect.Y + destRect.Y); _context.Rectangle (destRect.ToCairo ());
_context.Fill ();
_context.Rectangle (destRect.ToCairo ()); _context.PopGroupToSource ();
_context.Fill (); _context.PaintWithAlpha (opacityOverride);
_context.PopGroupToSource (); _context.Restore();
_context.PaintWithAlpha (opacityOverride);
} else {
_context.PushGroup ();
Gdk.CairoHelper.SetSourcePixbuf (
_context,
impl,
-sourceRect.X + destRect.X,
-sourceRect.Y + destRect.Y);
_context.Rectangle (destRect.ToCairo ());
_context.Fill ();
_context.PopGroupToSource ();
_context.PaintWithAlpha (opacityOverride);
}
_context.Restore();
} }
/// <summary> /// <summary>

Loading…
Cancel
Save