Added caching class to handle images
This commit is contained in:
parent
1465eead02
commit
c73fd4e058
@ -1,8 +1,10 @@
|
||||
using System;
|
||||
using Magazyn.Tools;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Media.Imaging;
|
||||
|
||||
namespace Magazyn.DataModels
|
||||
@ -79,6 +81,7 @@ namespace Magazyn.DataModels
|
||||
|
||||
public Fruit(int id, string name, int quantity, int quantityMax, float price, string imageLink)
|
||||
{
|
||||
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.quantity = quantity;
|
||||
@ -86,11 +89,7 @@ namespace Magazyn.DataModels
|
||||
this.price = price;
|
||||
this.imageLink = imageLink;
|
||||
|
||||
imageSource = new BitmapImage();
|
||||
imageSource.BeginInit();
|
||||
imageSource.UriSource = new Uri(imageLink);
|
||||
imageSource.CacheOption = BitmapCacheOption.OnLoad;
|
||||
imageSource.EndInit();
|
||||
imageSource = CacheImage.GetImageSource(new Uri(imageLink));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -67,6 +67,7 @@
|
||||
</ApplicationDefinition>
|
||||
<Compile Include="DataModels\Fruit.cs" />
|
||||
<Compile Include="DataModels\WarehousePrice.cs" />
|
||||
<Compile Include="Tools\CacheImage.cs" />
|
||||
<Compile Include="Views\FruitView.xaml.cs">
|
||||
<DependentUpon>FruitView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
|
@ -20,6 +20,7 @@ using Newtonsoft.Json.Linq;
|
||||
|
||||
using System.Net;
|
||||
using Magazyn.Windows;
|
||||
using Magazyn.Tools;
|
||||
|
||||
namespace Magazyn
|
||||
{
|
||||
|
29
Magazyn_Client/Magazyn/Tools/CacheImage.cs
Normal file
29
Magazyn_Client/Magazyn/Tools/CacheImage.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Media.Imaging;
|
||||
|
||||
namespace Magazyn.Tools
|
||||
{
|
||||
class CacheImage
|
||||
{
|
||||
static Dictionary<Uri, BitmapImage> dic = new Dictionary<Uri, BitmapImage>();
|
||||
|
||||
static public BitmapImage GetImageSource( Uri url )
|
||||
{
|
||||
if (dic.Keys.Contains<Uri>(url)) return dic[url];
|
||||
else
|
||||
{
|
||||
BitmapImage imageSource = new BitmapImage();
|
||||
imageSource.BeginInit();
|
||||
imageSource.UriSource = url;
|
||||
imageSource.CacheOption = BitmapCacheOption.OnLoad;
|
||||
imageSource.EndInit();
|
||||
dic.Add(url, imageSource);
|
||||
return imageSource;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user