-
Notifications
You must be signed in to change notification settings - Fork 3
/
PictureUtility.cs
90 lines (85 loc) · 2.6 KB
/
PictureUtility.cs
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
84
85
86
87
88
89
90
using System;
using System.Collections.Generic;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace Mob.Core
{
public static class PictureUtility
{
//contentType is not always available
//that's why we manually update it here
//http://www.sfsu.edu/training/mimetype.htm
public static string GetContentType(string fileExtension)
{
switch (fileExtension)
{
case ".bmp":
return "image/bmp";
case ".gif":
return "image/gif";
case ".jpeg":
case ".jpg":
case ".jpe":
case ".jfif":
case ".pjpeg":
case ".pjp":
return "image/jpeg";
case ".png":
return "image/png";
case ".tiff":
case ".tif":
return "image/tiff";
default:
return string.Empty;
}
}
public static string GetFileExtensionFromContentType(string contentType)
{
switch (contentType)
{
case "image/bmp":
return ".bmp";
case "image/gif":
return ".gif";
case "image/jpeg":
return ".jpg";
case "image/png":
return ".png";
case "image/tiff":
return ".tiff";
case "image/x-icon":
return ".ico";
}
return "";
}
/// <summary>
/// Gets image format from the content type
/// </summary>
/// <param name="contentType"></param>
/// <returns></returns>
public static ImageFormat GetImageFormatFromContentType(string contentType)
{
switch (contentType)
{
case "image/bmp":
return ImageFormat.Bmp; ;
case "image/gif":
return ImageFormat.Gif;
case "image/jpeg":
return ImageFormat.Jpeg;
case "image/png":
return ImageFormat.Png;
case "image/tiff":
return ImageFormat.Tiff;
case "image/x-icon":
return ImageFormat.Icon;
}
//default jpeg
return ImageFormat.Jpeg; ;
}
}
}