This repository was archived by the owner on Feb 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathImageResizer.cs
More file actions
73 lines (66 loc) · 2.54 KB
/
ImageResizer.cs
File metadata and controls
73 lines (66 loc) · 2.54 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
using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
namespace DevPro_CardManager
{
public static class ImageResizer
{
public static void SaveImage(string imagePath, string savedName,int width = 0, int height = 0)
{
Image originalImage = Image.FromFile(imagePath);
string filePath = AppDomain.CurrentDomain.BaseDirectory + savedName;
if (width > 0 && height > 0)
{
var myCallback =
new Image.GetThumbnailImageAbort(ThumbnailCallback);
var imageToSave = originalImage.GetThumbnailImage
(width, height, myCallback, IntPtr.Zero);
imageToSave.Save(filePath, System.Drawing.Imaging.ImageFormat.Jpeg);
}
else
{
originalImage.Save(filePath, System.Drawing.Imaging.ImageFormat.Jpeg);
}
}
public static void SaveImage(Image image, string savedName, int width = 0, int height = 0)
{
Image originalImage = image;
string filePath = AppDomain.CurrentDomain.BaseDirectory + savedName;
if (width > 0 && height > 0)
{
var myCallback =
new Image.GetThumbnailImageAbort(ThumbnailCallback);
Image imageToSave = originalImage.GetThumbnailImage
(width, height, myCallback, IntPtr.Zero);
imageToSave.Save(filePath, System.Drawing.Imaging.ImageFormat.Jpeg);
}
else
{
originalImage.Save(filePath, System.Drawing.Imaging.ImageFormat.Jpeg);
}
}
private static bool ThumbnailCallback() { return false; }
public static byte[] ImageToBinary(string imagePath)
{
var fileStream = new FileStream(imagePath, FileMode.Open, FileAccess.Read);
var buffer = new byte[fileStream.Length];
fileStream.Read(buffer, 0, (int)fileStream.Length);
fileStream.Close();
return buffer;
}
public static string OpenFileWindow(string title, string startpath, string filefilter)
{
var dialog = new OpenFileDialog();
dialog.InitialDirectory = startpath;
dialog.Title = title;
dialog.Filter = filefilter;
dialog.Multiselect = true;
if ((dialog.ShowDialog() == DialogResult.OK))
{
return dialog.FileName;
}
return null;
}
}
}