Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
ImageExtension.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 using System.Windows.Controls;
5 using System.Windows.Data;
6 using System.Windows.Markup;
7 using System.Windows.Media;
8 
9 namespace SiliconStudio.Presentation.MarkupExtensions
10 {
11  [MarkupExtensionReturnType(typeof(Image))]
13  {
14  private readonly ImageSource source;
15  private readonly int width;
16  private readonly int height;
17  private readonly BitmapScalingMode scalingMode;
18 
19  public ImageExtension(ImageSource source)
20  {
21  this.source = source;
22  width = -1;
23  height = -1;
24  }
25 
26  public ImageExtension(ImageSource source, int width, int height)
27  : this(source, width, height, BitmapScalingMode.Unspecified)
28  {
29  }
30 
31  public ImageExtension(ImageSource source, int width, int height, BitmapScalingMode scalingMode)
32  {
33  if (width < 0) throw new ArgumentOutOfRangeException("width");
34  if (height < 0) throw new ArgumentOutOfRangeException("height");
35  this.source = source;
36  this.width = width;
37  this.height = height;
38  this.scalingMode = scalingMode;
39  }
40 
41  public override object ProvideValue(IServiceProvider serviceProvider)
42  {
43  var image = new Image { Source = source };
44  RenderOptions.SetBitmapScalingMode(image, scalingMode);
45  if (width >= 0 && height >= 0)
46  {
47  image.Width = width;
48  image.Height = height;
49  }
50  return image;
51  }
52  }
53 }
ImageExtension(ImageSource source, int width, int height)
ImageExtension(ImageSource source, int width, int height, BitmapScalingMode scalingMode)
override object ProvideValue(IServiceProvider serviceProvider)