-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageFileInfoExtensions.cs
More file actions
45 lines (43 loc) · 1.33 KB
/
Copy pathImageFileInfoExtensions.cs
File metadata and controls
45 lines (43 loc) · 1.33 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
using System;
using ImageCore.Enums;
using ImageCore.Models;
using ImageCore.Persistence.EntityFramework;
namespace ImageApi.Core
{
public static class ImageFileInfoExtensions
{
public static ImageDto ToImage(this ImageFileInfo fileInfo)
{
ImageFormat imageFormat;
switch (fileInfo.Extension)
{
case ".jpg":
imageFormat = ImageFormat.Jpeg;
break;
case ".gif":
imageFormat = ImageFormat.Gif;
break;
case ".bmp":
imageFormat = ImageFormat.Bmp;
break;
case ".png":
imageFormat = ImageFormat.Png;
break;
default:
throw new Exception("此文件不是图片类型");
}
var image = new ImageDto()
{
Format = imageFormat,
Length = fileInfo.Length,
Bytes = fileInfo.FileBytes,
CreateTime = DateTime.Now,
Name = fileInfo.FileName,
BusinessType = BusinessType.Default,
Width = fileInfo.Size.Width,
Height = fileInfo.Size.Height
};
return image;
}
}
}