日期:2014-05-17 浏览次数:21081 次
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
namespace Test.Common
{
/// <summary>
/// 提供图片转换工具
/// </summary>
public static class ImageTransUtility
{
/// <summary>
/// 该函数提供等比转换功能、图片仅进行压缩,不进行裁切.
/// </summary>
/// <param name="sourceFileName"></param>
/// <param name="targetFileName"></param>
/// <param name="maxWidth"></param>
/// <param name="maxHeight"></param>
public static void TranslateByEqualRatio(string sourceFileName, string targetFileName, int maxWidth, int maxHeight)
{
if (maxWidth <= 0
------解决方案--------------------
maxHeight <= 0)
{
throw new ArgumentException("Width And Height Must More than zero");
}
Bitmap fullSizeImg = new Bitmap(sourceFileName);
int width = fullSizeImg.Width;
int height = fullSizeImg.Height;
if (width > maxWidth
------解决方案--------------------
height > maxHeight)
{
if (maxWidth - width < maxHeight - height)
{
&n