-
Notifications
You must be signed in to change notification settings - Fork 0
/
IPCore.cs
74 lines (67 loc) · 2.15 KB
/
IPCore.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
using ImageProcessor.Processors;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Media.Imaging;
namespace ImageProcessor
{
public sealed class IPCore
{
private static List<Type> processorTypes = new List<Type>();
public static Type[] ProcessorTypes => processorTypes.ToArray();
public static void Startup()
{
ProxifierFactory.RegisterProxifiers();
Type[] types = Assembly.GetExecutingAssembly().GetTypes();
foreach (Type type in types)
{
if (type.GetCustomAttributes(true).Any((a) => a is ImageProcessorAttribute))
{
processorTypes.Add(type);
}
}
}
public static string GetProcessorTypeName(Type p)
{
var attr = p.GetCustomAttribute<ImageProcessorAttribute>(true);
if (attr != null)
{
return attr.Name;
}
else
{
throw new ArgumentNullException("Type has no attributes of ImageProcessor");
}
}
public static Image MakeProcessedImage(Image source, IEnumerable<Processors.Processor> processors)
{
var im = source;
foreach (var p in processors)
{
im = p.ProcessImage(im);
}
return im;
}
[DllImport("gdi32")]
private static extern bool DeleteObject(IntPtr obj);
public static BitmapSource GetBitmapSourceFromImage(Image originalImage)
{
Bitmap bitmap = new Bitmap(originalImage);
IntPtr hBits = bitmap.GetHbitmap();
BitmapSource bs = Imaging.CreateBitmapSourceFromHBitmap(
hBits,
IntPtr.Zero,
Int32Rect.Empty,
BitmapSizeOptions.FromEmptyOptions());
DeleteObject(hBits);
return bs;
}
}
}