views:

396

answers:

2

Hi,

I'm looking almost hour for examples of using imagemagick.net in c# and I can't find antything.

All what I need is resize image (.jpg) to new size image (jpg, too) and would be great if you known how to add watermark.

I downloaded imagemagick.net from

http://imagemagick.codeplex.com/

A: 

This is a .net application written in c# that utilises the ImageMagick command line application to allow conversion of multiple image formats to different formats.
Also you can see how to write the wrapper here.
About watermarks: you can use my project, by the way suggest improvements if you want :) I'll implement them if i have time..For now the project had no updates for long time, because i had no motivation to update it (though noone needs it)

nihi_l_ist
I know this links but I don't know VB and I don't want only application.
I don't know VB too, but there is not much difference in code between it and C#..Just operators. I saw the the article and suggest read from "Using ImageMagick from VB.NET" section. The code is understandable for C# developer i think..In sections before its C++
nihi_l_ist
by the way, why do you want to use ImageMagik?..all this can be done with Graphics, Image or Bitmap class.
nihi_l_ist
I know about this class, but out designers want to use this library...
+2  A: 

Do you have to use ImageMagick? You can use GDI+ if your aim is to redeliver an image in another size. http://www.switchonthecode.com/tutorials/csharp-tutorial-image-editing-saving-cropping-and-resizing gives this function for resizing. I've used this tutorial in the past for watermarking: http://www.codeproject.com/KB/GDI-plus/watermark.aspx

private  static Image resizeImage(Image imgToResize, Size size)
{
int sourceWidth = imgToResize.Width;
int sourceHeight = imgToResize.Height;

float nPercent = 0;
float nPercentW = 0;
float nPercentH = 0;

nPercentW = ((float)size.Width / (float)sourceWidth);
nPercentH = ((float)size.Height / (float)sourceHeight);

if (nPercentH < nPercentW)
  nPercent = nPercentH;
 else
  nPercent = nPercentW;

int destWidth = (int)(sourceWidth * nPercent);
int destHeight = (int)(sourceHeight * nPercent);

Bitmap b = new Bitmap(destWidth, destHeight);
Graphics g = Graphics.FromImage((Image)b);
g.InterpolationMode = InterpolationMode.HighQualityBicubic;

g.DrawImage(imgToResize, 0, 0, destWidth, destHeight);
g.Dispose();

return (Image)b;
}
David