├── photo
├── balon.jpg
├── micha.jpg
├── robbie.jpg
├── robbie2.jpg
├── robbie3.jpg
├── friends2.jpg
└── motherboard.jpg
├── Keys.cs
├── packages.config
├── ImageProcessorSample.sln
├── Properties
└── AssemblyInfo.cs
├── ImageProcessorSample.csproj
├── Program.cs
└── .gitignore
/photo/balon.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thatcsharpguy/ImageProcessor-Sample/master/photo/balon.jpg
--------------------------------------------------------------------------------
/photo/micha.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thatcsharpguy/ImageProcessor-Sample/master/photo/micha.jpg
--------------------------------------------------------------------------------
/photo/robbie.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thatcsharpguy/ImageProcessor-Sample/master/photo/robbie.jpg
--------------------------------------------------------------------------------
/photo/robbie2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thatcsharpguy/ImageProcessor-Sample/master/photo/robbie2.jpg
--------------------------------------------------------------------------------
/photo/robbie3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thatcsharpguy/ImageProcessor-Sample/master/photo/robbie3.jpg
--------------------------------------------------------------------------------
/photo/friends2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thatcsharpguy/ImageProcessor-Sample/master/photo/friends2.jpg
--------------------------------------------------------------------------------
/photo/motherboard.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/thatcsharpguy/ImageProcessor-Sample/master/photo/motherboard.jpg
--------------------------------------------------------------------------------
/Keys.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | namespace ImageProcessorSample
3 | {
4 | public static class Keys
5 | {
6 | public const string CognitiveServices = ""; // Request a key here: https://www.microsoft.com/cognitive-services/en-us/face-api/documentation/overview
7 | }
8 | }
9 |
10 |
--------------------------------------------------------------------------------
/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/ImageProcessorSample.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2012
4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImageProcessorSample", "ImageProcessorSample.csproj", "{C00AE807-848D-4C7A-94F6-6281BB972FC5}"
5 | EndProject
6 | Global
7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
8 | Debug|x86 = Debug|x86
9 | Release|x86 = Release|x86
10 | EndGlobalSection
11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
12 | {C00AE807-848D-4C7A-94F6-6281BB972FC5}.Debug|x86.ActiveCfg = Debug|x86
13 | {C00AE807-848D-4C7A-94F6-6281BB972FC5}.Debug|x86.Build.0 = Debug|x86
14 | {C00AE807-848D-4C7A-94F6-6281BB972FC5}.Release|x86.ActiveCfg = Release|x86
15 | {C00AE807-848D-4C7A-94F6-6281BB972FC5}.Release|x86.Build.0 = Release|x86
16 | EndGlobalSection
17 | EndGlobal
18 |
--------------------------------------------------------------------------------
/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 |
4 | // Information about this assembly is defined by the following attributes.
5 | // Change them to the values specific to your project.
6 |
7 | [assembly: AssemblyTitle("ImageProcessorSample")]
8 | [assembly: AssemblyDescription("")]
9 | [assembly: AssemblyConfiguration("")]
10 | [assembly: AssemblyCompany("")]
11 | [assembly: AssemblyProduct("")]
12 | [assembly: AssemblyCopyright("fferegrino")]
13 | [assembly: AssemblyTrademark("")]
14 | [assembly: AssemblyCulture("")]
15 |
16 | // The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
17 | // The form "{Major}.{Minor}.*" will automatically update the build and revision,
18 | // and "{Major}.{Minor}.{Build}.*" will update just the revision.
19 |
20 | [assembly: AssemblyVersion("1.0.*")]
21 |
22 | // The following attributes are used to specify the signing key for the assembly,
23 | // if desired. See the Mono documentation for more information about signing.
24 |
25 | //[assembly: AssemblyDelaySign(false)]
26 | //[assembly: AssemblyKeyFile("")]
27 |
28 |
--------------------------------------------------------------------------------
/ImageProcessorSample.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | x86
6 | {C00AE807-848D-4C7A-94F6-6281BB972FC5}
7 | Exe
8 | ImageProcessorSample
9 | ImageProcessorSample
10 | v4.5
11 |
12 |
13 | true
14 | full
15 | false
16 | bin\Debug
17 | DEBUG;
18 | prompt
19 | 4
20 | true
21 | x86
22 |
23 |
24 | true
25 | bin\Release
26 | prompt
27 | 4
28 | true
29 | x86
30 |
31 |
32 |
33 |
34 | packages\ImageProcessor.2.4.3.0\lib\net45\ImageProcessor.dll
35 |
36 |
37 |
38 | packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll
39 |
40 |
41 | packages\Microsoft.ProjectOxford.Face.1.1.0\lib\portable-net45+wp80+win8+wpa81+aspnetcore50\Microsoft.ProjectOxford.Face.dll
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 | Always
53 |
54 |
55 | Always
56 |
57 |
58 | Always
59 |
60 |
61 | Always
62 |
63 |
64 | Always
65 |
66 |
67 | Always
68 |
69 |
70 | Always
71 |
72 |
73 |
74 |
--------------------------------------------------------------------------------
/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Drawing;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Threading.Tasks;
6 | using ImageProcessor;
7 | using ImageProcessor.Imaging.Filters.Photo;
8 | using ImageProcessor.Imaging.Formats;
9 | using Microsoft.ProjectOxford.Face;
10 | using Microsoft.ProjectOxford.Face.Contract;
11 |
12 | namespace ImageProcessorSample
13 | {
14 | class MainClass
15 | {
16 | public static void Main(string[] args)
17 | {
18 | var balonBytes = File.ReadAllBytes("photo/balon.jpg");
19 |
20 | using (var inStream = new MemoryStream(balonBytes))
21 | using (var imageFactory = new ImageFactory(false))
22 | {
23 | Console.WriteLine("Working on balon.jpg");
24 |
25 | // Resize
26 | var img = imageFactory.Load(inStream);
27 | img.Resize(new Size(300, 0));
28 | img.Save("photo/bolaResized.jpg");
29 |
30 | //imageFactory.Load(inStream)
31 | // .Resize(new Size(300, 0))
32 | // .Save("photo/bolaResized.jpg");
33 |
34 | // Lower quality
35 | imageFactory.Load(inStream)
36 | .Quality(5) // Only works with jpg
37 | .Save("photo/bolaLow.jpg");
38 |
39 | // Change format
40 | imageFactory.Load(inStream)
41 | .Format(new PngFormat { Quality = 10 })
42 | .Save("photo/balon.png");
43 |
44 | }
45 |
46 |
47 | var michaBytes = File.ReadAllBytes("photo/micha.jpg");
48 |
49 | using (var inStream = new MemoryStream(michaBytes))
50 | using (var imageFactory = new ImageFactory(false))
51 | {
52 | Console.WriteLine("Working on micha.jpg");
53 |
54 | // Make a Micha cool portrait
55 | imageFactory.Load(inStream)
56 | .Filter(MatrixFilters.HiSatch)
57 | .Save("photo/michaArt.jpg");
58 |
59 | // Invert-a Micha
60 | imageFactory.Load(inStream)
61 | .Filter(MatrixFilters.Invert)
62 | .Save("photo/michaInverse.jpg");
63 |
64 | // Michstagram
65 | imageFactory.Load(inStream)
66 | .Filter(MatrixFilters.Sepia)
67 | .Tint(Color.LightSalmon)
68 | .Saturation(50)
69 | .Save("photo/michaInstagram.jpg");
70 |
71 | }
72 |
73 |
74 | var motherBoardBytes = File.ReadAllBytes("photo/motherboard.jpg");
75 |
76 | using (var inStream = new MemoryStream(motherBoardBytes))
77 | using (var imageFactory = new ImageFactory(false))
78 | {
79 | Console.WriteLine("Working on motherboard.jpg");
80 |
81 | // Cropping
82 | var m = imageFactory.Load(inStream)
83 | .Crop(new Rectangle(100, 100, 250, 250))
84 | .Save("photo/motherboardCropped.jpg");
85 |
86 | m.Rotate(10f)
87 | .Save("photo/motherboardRotated.jpg");
88 |
89 | m.Flip(true, true)
90 | .Save("photo/motherboardFlipped.jpg");
91 |
92 | }
93 |
94 |
95 |
96 | // Cognitive services:
97 | if (!String.IsNullOrEmpty(Keys.CognitiveServices))
98 | {
99 | FaceServiceClient faceServiceClient = new FaceServiceClient(Keys.CognitiveServices);
100 |
101 |
102 | // Cropping faces:
103 | var robbieBytes = File.ReadAllBytes("photo/robbie3.jpg");
104 |
105 | Console.WriteLine("Working on robbie3.jpg");
106 |
107 | Face face = null;
108 |
109 | using (var inStream = new MemoryStream(robbieBytes))
110 | {
111 | var detectionTask = faceServiceClient.DetectAsync(inStream);
112 | detectionTask.Wait();
113 | face = detectionTask.Result.FirstOrDefault();
114 | }
115 |
116 | if (face != null)
117 | {
118 | var faceContainer = new Rectangle(face.FaceRectangle.Left, face.FaceRectangle.Top, face.FaceRectangle.Width, face.FaceRectangle.Height);
119 | using (var inStream = new MemoryStream(robbieBytes))
120 | using (var imageFactory = new ImageFactory(false))
121 | {
122 | imageFactory.Load(inStream)
123 | .Crop(faceContainer)
124 | .Save("photo/robbieFace.jpg");
125 | }
126 | }
127 |
128 |
129 | // Pixelate faces:
130 | var friendsBytes = File.ReadAllBytes("photo/friends2.jpg");
131 |
132 | Console.WriteLine("Working on friends2.jpg");
133 | Face[] faces;
134 |
135 | using (var inStream = new MemoryStream(friendsBytes))
136 | {
137 | var detectionTask = faceServiceClient.DetectAsync(inStream);
138 | detectionTask.Wait();
139 | faces = detectionTask.Result;
140 | }
141 |
142 | using (var inStream = new MemoryStream(friendsBytes))
143 | using (var imageFactory = new ImageFactory(false))
144 | {
145 | var friendsImage = imageFactory.Load(inStream);
146 | foreach (var f in faces)
147 | {
148 | var faceContainer = new Rectangle(f.FaceRectangle.Left, f.FaceRectangle.Top, f.FaceRectangle.Width, f.FaceRectangle.Height);
149 | friendsImage.Pixelate(20, faceContainer);
150 | }
151 | friendsImage.Save("photo/friendsAnonymous.jpg");
152 | }
153 | }
154 |
155 | Console.WriteLine("Done, press any key.");
156 | Console.Read();
157 | }
158 | }
159 | }
160 |
161 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | x64/
19 | x86/
20 | bld/
21 | [Bb]in/
22 | [Oo]bj/
23 | [Ll]og/
24 |
25 | # Visual Studio 2015 cache/options directory
26 | .vs/
27 | # Uncomment if you have tasks that create the project's static files in wwwroot
28 | #wwwroot/
29 |
30 | # MSTest test Results
31 | [Tt]est[Rr]esult*/
32 | [Bb]uild[Ll]og.*
33 |
34 | # NUNIT
35 | *.VisualState.xml
36 | TestResult.xml
37 |
38 | # Build Results of an ATL Project
39 | [Dd]ebugPS/
40 | [Rr]eleasePS/
41 | dlldata.c
42 |
43 | # DNX
44 | project.lock.json
45 | artifacts/
46 |
47 | *_i.c
48 | *_p.c
49 | *_i.h
50 | *.ilk
51 | *.meta
52 | *.obj
53 | *.pch
54 | *.pdb
55 | *.pgc
56 | *.pgd
57 | *.rsp
58 | *.sbr
59 | *.tlb
60 | *.tli
61 | *.tlh
62 | *.tmp
63 | *.tmp_proj
64 | *.log
65 | *.vspscc
66 | *.vssscc
67 | .builds
68 | *.pidb
69 | *.svclog
70 | *.scc
71 |
72 | # Chutzpah Test files
73 | _Chutzpah*
74 |
75 | # Visual C++ cache files
76 | ipch/
77 | *.aps
78 | *.ncb
79 | *.opendb
80 | *.opensdf
81 | *.sdf
82 | *.cachefile
83 | *.VC.db
84 | *.VC.VC.opendb
85 |
86 | # Visual Studio profiler
87 | *.psess
88 | *.vsp
89 | *.vspx
90 | *.sap
91 |
92 | # TFS 2012 Local Workspace
93 | $tf/
94 |
95 | # Guidance Automation Toolkit
96 | *.gpState
97 |
98 | # ReSharper is a .NET coding add-in
99 | _ReSharper*/
100 | *.[Rr]e[Ss]harper
101 | *.DotSettings.user
102 |
103 | # JustCode is a .NET coding add-in
104 | .JustCode
105 |
106 | # TeamCity is a build add-in
107 | _TeamCity*
108 |
109 | # DotCover is a Code Coverage Tool
110 | *.dotCover
111 |
112 | # NCrunch
113 | _NCrunch_*
114 | .*crunch*.local.xml
115 | nCrunchTemp_*
116 |
117 | # MightyMoose
118 | *.mm.*
119 | AutoTest.Net/
120 |
121 | # Web workbench (sass)
122 | .sass-cache/
123 |
124 | # Installshield output folder
125 | [Ee]xpress/
126 |
127 | # DocProject is a documentation generator add-in
128 | DocProject/buildhelp/
129 | DocProject/Help/*.HxT
130 | DocProject/Help/*.HxC
131 | DocProject/Help/*.hhc
132 | DocProject/Help/*.hhk
133 | DocProject/Help/*.hhp
134 | DocProject/Help/Html2
135 | DocProject/Help/html
136 |
137 | # Click-Once directory
138 | publish/
139 |
140 | # Publish Web Output
141 | *.[Pp]ublish.xml
142 | *.azurePubxml
143 | # TODO: Comment the next line if you want to checkin your web deploy settings
144 | # but database connection strings (with potential passwords) will be unencrypted
145 | *.pubxml
146 | *.publishproj
147 |
148 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
149 | # checkin your Azure Web App publish settings, but sensitive information contained
150 | # in these scripts will be unencrypted
151 | PublishScripts/
152 |
153 | # NuGet Packages
154 | *.nupkg
155 | # The packages folder can be ignored because of Package Restore
156 | **/packages/*
157 | # except build/, which is used as an MSBuild target.
158 | !**/packages/build/
159 | # Uncomment if necessary however generally it will be regenerated when needed
160 | #!**/packages/repositories.config
161 | # NuGet v3's project.json files produces more ignoreable files
162 | *.nuget.props
163 | *.nuget.targets
164 |
165 | # Microsoft Azure Build Output
166 | csx/
167 | *.build.csdef
168 |
169 | # Microsoft Azure Emulator
170 | ecf/
171 | rcf/
172 |
173 | # Windows Store app package directories and files
174 | AppPackages/
175 | BundleArtifacts/
176 | Package.StoreAssociation.xml
177 | _pkginfo.txt
178 |
179 | # Visual Studio cache files
180 | # files ending in .cache can be ignored
181 | *.[Cc]ache
182 | # but keep track of directories ending in .cache
183 | !*.[Cc]ache/
184 |
185 | # Others
186 | ClientBin/
187 | ~$*
188 | *~
189 | *.dbmdl
190 | *.dbproj.schemaview
191 | *.pfx
192 | *.publishsettings
193 | node_modules/
194 | orleans.codegen.cs
195 |
196 | # Since there are multiple workflows, uncomment next line to ignore bower_components
197 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
198 | #bower_components/
199 |
200 | # RIA/Silverlight projects
201 | Generated_Code/
202 |
203 | # Backup & report files from converting an old project file
204 | # to a newer Visual Studio version. Backup files are not needed,
205 | # because we have git ;-)
206 | _UpgradeReport_Files/
207 | Backup*/
208 | UpgradeLog*.XML
209 | UpgradeLog*.htm
210 |
211 | # SQL Server files
212 | *.mdf
213 | *.ldf
214 |
215 | # Business Intelligence projects
216 | *.rdl.data
217 | *.bim.layout
218 | *.bim_*.settings
219 |
220 | # Microsoft Fakes
221 | FakesAssemblies/
222 |
223 | # GhostDoc plugin setting file
224 | *.GhostDoc.xml
225 |
226 | # Node.js Tools for Visual Studio
227 | .ntvs_analysis.dat
228 |
229 | # Visual Studio 6 build log
230 | *.plg
231 |
232 | # Visual Studio 6 workspace options file
233 | *.opt
234 |
235 | # Visual Studio LightSwitch build output
236 | **/*.HTMLClient/GeneratedArtifacts
237 | **/*.DesktopClient/GeneratedArtifacts
238 | **/*.DesktopClient/ModelManifest.xml
239 | **/*.Server/GeneratedArtifacts
240 | **/*.Server/ModelManifest.xml
241 | _Pvt_Extensions
242 |
243 | # Paket dependency manager
244 | .paket/paket.exe
245 | paket-files/
246 |
247 | # FAKE - F# Make
248 | .fake/
249 |
250 | # JetBrains Rider
251 | .idea/
252 | *.sln.iml
253 |
--------------------------------------------------------------------------------