如何使用imagemagick.net在.net中? [英] How to use imagemagick.net in .net ?
问题描述
我在寻找几乎每小时在C#中使用imagemagick.net的例子,我找不到antything。
I'm looking almost hour for examples of using imagemagick.net in c# and I can't find antything.
所有我需要的是调整图像(.JPG)新大小的图片(JPG,太),如果你知道如何添加水印将是巨大的。
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.
我下载imagemagick.net从
I downloaded imagemagick.net from
HTTP://imagemagick.$c$cplex.com/
推荐答案
你有使用ImageMagick的?您可以使用GDI +,如果你的目的是要在其他尺寸重新发货的图像。 <一href=\"http://www.switchonthe$c$c.com/tutorials/csharp-tutorial-image-editing-saving-cropping-and-resizing\" rel=\"nofollow\">http://www.switchonthe$c$c.com/tutorials/csharp-tutorial-image-editing-saving-cropping-and-resizing使此功能调整。我用这个教程在过去的水印:的http:// WWW。codeproject.com / KB / GDI加/ watermark.aspx
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;
}
这篇关于如何使用imagemagick.net在.net中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!