-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathImageStorage.cs
More file actions
83 lines (70 loc) · 2.04 KB
/
Copy pathImageStorage.cs
File metadata and controls
83 lines (70 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using Android.Content;
using Android.Graphics;
using Android.Provider;
using System.Collections.Generic;
using System.Net;
namespace TouchWalkthrough
{
public class ImageStorage
{
// Singelton-part
private static ImageStorage instance;
private ImageStorage()
{
images = new Dictionary<string, Bitmap>();
}
public static ImageStorage Instance
{
get
{
if (instance == null)
{
instance = new ImageStorage();
}
return instance;
}
}
// Storage-part
private static Dictionary<string, Bitmap> images;
public Bitmap getBitmap(string path)
{
Bitmap bitmap;
images.TryGetValue(path, out bitmap);
return bitmap;
}
public void addBitmap(string path, Bitmap bitmap)
{
images.Add(path, bitmap);
}
public void addURL(string path)
{
if (path != null && !images.ContainsKey(path))
{
try
{
Bitmap bitmap = GetImageBitmapFromUrl(path);
addBitmap(path, bitmap);
}
catch (System.Net.WebException) { }
}
}
private Bitmap GetImageBitmapFromUrl(string url)
{
Bitmap imageBitmap = null;
using (var webClient = new WebClient())
{
var imageBytes = webClient.DownloadData(url);
if (imageBytes != null && imageBytes.Length > 0)
{
imageBitmap = BitmapFactory.DecodeByteArray(imageBytes, 0, imageBytes.Length);
}
}
return imageBitmap;
}
public void addURI(string path, Android.Net.Uri uri, ContentResolver cr)
{
Bitmap bitmap = MediaStore.Images.Media.GetBitmap(cr, uri);
addBitmap(path, bitmap);
}
}
}