如何在 .net 中使用 imagemagick.net? [英] How to use imagemagick.net in .net ?

查看:26
本文介绍了如何在 .net 中使用 imagemagick.net?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我几乎花了一个小时来寻找在 c# 中使用 imagemagick.net 的示例,但我找不到任何东西.

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.

我从

http://imagemagick.codeplex.com/

推荐答案

你必须使用 ImageMagick 吗?如果您的目标是重新传送其他尺寸的图像,则可以使用 GDI+.http://www.switchonthecode.com/教程/csharp-tutorial-image-editing-saving-cropping-and-resizing 提供了这个调整大小的功能.我过去曾使用本教程进行水印:http://www.codeproject.com/KB/GDI-plus/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;
}

这篇关于如何在 .net 中使用 imagemagick.net?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆