Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
More code + resizing and properties.
- Loading branch information
1 parent
ae527c5
commit c8e6b44
Showing
8 changed files
with
159 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System; | ||
using System.Linq; | ||
|
||
namespace NImageMagick | ||
{ | ||
public enum FilterType | ||
{ | ||
UndefinedFilter, | ||
PointFilter, | ||
BoxFilter, | ||
TriangleFilter, | ||
HermiteFilter, | ||
HanningFilter, | ||
HammingFilter, | ||
BlackmanFilter, | ||
GaussianFilter, | ||
QuadraticFilter, | ||
CubicFilter, | ||
CatromFilter, | ||
MitchellFilter, | ||
JincFilter, | ||
SincFilter, | ||
SincFastFilter, | ||
KaiserFilter, | ||
WelshFilter, | ||
ParzenFilter, | ||
BohmanFilter, | ||
BartlettFilter, | ||
LagrangeFilter, | ||
LanczosFilter, | ||
LanczosSharpFilter, | ||
Lanczos2Filter, | ||
Lanczos2SharpFilter, | ||
RobidouxFilter, | ||
RobidouxSharpFilter, | ||
CosineFilter, | ||
SplineFilter, | ||
SentinelFilter /* a count of all the filters, not a real filter */ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,87 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace NImageMagick | ||
{ | ||
public class Image | ||
public class Image : IDisposable | ||
{ | ||
private IntPtr handle; | ||
public IntPtr Handle { get; private set; } | ||
|
||
public IntPtr Handle | ||
public int ImageCompressionQuality | ||
{ | ||
get { return this.handle; } | ||
get | ||
{ | ||
return (int)ImageMagick.MagickGetImageCompressionQuality(this.Handle); | ||
} | ||
set | ||
{ | ||
this.ExecuteChecked(ImageMagick.MagickSetImageCompressionQuality, (uint)value); | ||
} | ||
} | ||
|
||
public int Width | ||
{ | ||
get | ||
{ | ||
return (int)ImageMagick.MagickGetImageWidth(this.Handle); | ||
} | ||
} | ||
|
||
public int Height | ||
{ | ||
get | ||
{ | ||
return (int)ImageMagick.MagickGetImageHeight(this.Handle); | ||
} | ||
} | ||
|
||
public Image(string path) | ||
{ | ||
ImageMagick.EnsureInitialized(); | ||
handle = ImageMagick.NewMagickWand(); | ||
if (handle == IntPtr.Zero) | ||
Handle = ImageMagick.NewMagickWand(); | ||
if (Handle == IntPtr.Zero) | ||
{ | ||
throw new Exception("Error acquiring wand."); | ||
} | ||
IntPtr str = ImageMagick.AllocateUTF8String(path); | ||
int result = ImageMagick.MagickReadImage(this.handle, str); | ||
ImageMagick.FreeString(str); | ||
|
||
if (result == 0) | ||
using (NativeString pathString = new NativeString(path)) | ||
{ | ||
throw new ImageMagickException(this.handle); | ||
this.ExecuteChecked(ImageMagick.MagickReadImage, pathString.Pointer); | ||
} | ||
} | ||
|
||
public void ExecuteChecked<T>(Func<IntPtr, T, int> action, T param1) | ||
{ | ||
if (action(this.Handle, param1) != 1) | ||
{ | ||
throw new ImageMagickException(this.Handle); | ||
} | ||
} | ||
|
||
public void ExecuteChecked<T1, T2, T3, T4>(Func<IntPtr, T1, T2, T3, T4, int> action, T1 param1, T2 param2, T3 param3, T4 param4) | ||
{ | ||
if (action(this.Handle, param1, param2, param3, param4) != 1) | ||
{ | ||
throw new ImageMagickException(this.Handle); | ||
} | ||
} | ||
|
||
public void Save(string path) | ||
{ | ||
using (NativeString pathString = new NativeString(path)) | ||
{ | ||
this.ExecuteChecked(ImageMagick.MagickWriteImage, pathString.Pointer); | ||
} | ||
} | ||
|
||
public void Resize(int width, int height, FilterType filterType, double blur) | ||
{ | ||
this.ExecuteChecked(ImageMagick.MagickResizeImage, (uint)width, (uint)height, (int)filterType, blur); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
this.Handle = ImageMagick.DestroyMagickWand(this.Handle); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<ProjectView>ProjectFiles</ProjectView> | ||
</PropertyGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters