-
Notifications
You must be signed in to change notification settings - Fork 0
/
library.cs
45 lines (39 loc) · 1.28 KB
/
library.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
using System;
namespace EncryptedGallery
{
class library
{
public static byte[] DecodeHex(string hextext)
{
String[] arr = hextext.Split('-');
byte[] array = new byte[arr.Length];
for (int i = 0; i < arr.Length; i++)
array[i] = Convert.ToByte(arr[i], 16);
return array;
}
public static bool IsPrime(int number)
{
if (number < 2) return false;
if (number % 2 == 0) return (number == 2);
int root = (int)Math.Sqrt((double)number);
for (int i = 3; i <= root; i += 2)
{
if (number % i == 0)
return false;
}
return true;
}
public static Bitmap ConvertByteToImage(byte[] bytes)
{
return (new Bitmap(Image.FromStream(new MemoryStream(bytes))));
}
public static byte[] ConvertImageToByte(Image My_Image)
{
MemoryStream m1 = new MemoryStream();
new Bitmap(My_Image).Save(m1, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] header = new byte[] { 255, 216 };
header = m1.ToArray();
return (header);
}
}
}