Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
ImageExtensions.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.Collections.Generic;
5 using System.Linq;
6 using System.Text;
7 using System.Threading.Tasks;
8 using System.Windows.Controls;
9 using System.Windows.Media;
10 using System.Windows.Media.Imaging;
11 
12 namespace SiliconStudio.Presentation.Extensions
13 {
14  public static class ImageExtensions
15  {
16  public static void SetSource(this Image image, Uri uri)
17  {
18  if (image == null)
19  throw new ArgumentNullException("image");
20  if (uri == null)
21  throw new ArgumentNullException("uri");
22 
23  image.Source = ImageSourceFromFile(uri);
24  }
25 
26  public static void SetSource(this Image image, string uri)
27  {
28  if (string.IsNullOrWhiteSpace(uri))
29  throw new ArgumentException("Invalid 'uri' argument.");
30 
31  SetSource(image, new Uri(uri));
32  }
33 
34  public static ImageSource ImageSourceFromFile(Uri uri)
35  {
36  if (uri == null)
37  throw new ArgumentNullException("uri");
38 
39  var source = new BitmapImage();
40  source.BeginInit();
41  source.UriSource = uri;
42  source.CacheOption = BitmapCacheOption.OnLoad;
43  source.EndInit();
44 
45  return source;
46  }
47 
48  public static ImageSource ImageSourceFromFile(string uri)
49  {
50  if (string.IsNullOrWhiteSpace(uri))
51  throw new ArgumentException("Invalid 'uri' argument.");
52 
53  return ImageSourceFromFile(new Uri(uri));
54  }
55  }
56 }
Android.Net.Uri Uri
Definition: HtmlElement.cs:8
static void SetSource(this Image image, Uri uri)
static void SetSource(this Image image, string uri)