C# ImageResizer-支持maxWidth&;最大高度->;平均保持纵横比

C# ImageResizer-支持maxWidth&;最大高度->;平均保持纵横比,c#,asp.net,image-resizing,aspect-ratio,C#,Asp.net,Image Resizing,Aspect Ratio,我正在寻找下面这样一个支持MaxWidth和MaxHeight的ImageResizer… 在哪里可以找到它? 下面的模块完成了我不需要的许多其他工作。 只想改变格式&支持maxwidth和maxheight 如果库的功能超出了您的需要,这并不重要。如果它做了你需要的,就用它。这些额外的东西不会损害你的健康。如果图书馆的功能超出了你的需要,这并不重要。如果它做了你需要的,就用它。额外的东西根本不会损害您的利益。您可以编写一个包装器,强制执行最大宽度和最大高度,并保持纵横比 例如,假设您有一个64

我正在寻找下面这样一个支持MaxWidth和MaxHeight的ImageResizer…
在哪里可以找到它?
下面的模块完成了我不需要的许多其他工作。
只想改变格式&支持maxwidth和maxheight


如果库的功能超出了您的需要,这并不重要。如果它做了你需要的,就用它。这些额外的东西不会损害你的健康。

如果图书馆的功能超出了你的需要,这并不重要。如果它做了你需要的,就用它。额外的东西根本不会损害您的利益。

您可以编写一个包装器,强制执行最大宽度和最大高度,并保持纵横比

例如,假设您有一个640 x 120的图像,最大值为1920 x 1440。现在,您希望使该图像尽可能大,因此您可以编写:

ResizeImage(图像,19201440)

如果你这样做的话,纵横比就会被拍摄下来

您需要计算现有图像的纵横比并调整值

// Compute existing aspect ratio
double aspectRatio = (double)image.Width / image.Height;

// Clip the desired values to the maximums
desiredHeight = Math.Min(desiredHeight, MaxHeight);
desiredWidth = Math.Min(desiredWidth, MaxWidth);

// This is the aspect ratio if you used the desired values.
double newAspect = (double)desiredWidth / desiredHeight;

if (newAspect > aspectRatio)
{
    // The new aspect ratio would make the image too tall.
    // Need to adjust the height.
    desiredHeight = (int)(desiredWidth / aspectRatio);
}
else if (newAspect < aspectRatio)
{
    // The new aspect ratio would make the image too wide.
    // Need to adjust the width.
    desiredWidth = (int)(desiredHeight * aspectRatio);
}

// You can now resize the image using desiredWidth and desiredHeight
//计算现有纵横比
double aspectRatio=(double)image.Width/image.Height;
//将所需值剪裁到最大值
desiredHeight=Math.Min(desiredHeight,MaxHeight);
desiredWidth=Math.Min(desiredWidth,MaxWidth);
//这是使用所需值时的纵横比。
双新宽=(双)所需宽度/所需高度;
如果(新方面>方面)
{
//新的纵横比会使图像太高。
//需要调整高度。
desiredHeight=(int)(desiredWidth/aspectRatio);
}
else if(新特性
您可以编写一个包装器来强制执行最大宽度和最大高度,并保持纵横比

例如,假设您有一个640 x 120的图像,最大值为1920 x 1440。现在,您希望使该图像尽可能大,因此您可以编写:

ResizeImage(图像,19201440)

如果你这样做的话,纵横比就会被拍摄下来

您需要计算现有图像的纵横比并调整值

// Compute existing aspect ratio
double aspectRatio = (double)image.Width / image.Height;

// Clip the desired values to the maximums
desiredHeight = Math.Min(desiredHeight, MaxHeight);
desiredWidth = Math.Min(desiredWidth, MaxWidth);

// This is the aspect ratio if you used the desired values.
double newAspect = (double)desiredWidth / desiredHeight;

if (newAspect > aspectRatio)
{
    // The new aspect ratio would make the image too tall.
    // Need to adjust the height.
    desiredHeight = (int)(desiredWidth / aspectRatio);
}
else if (newAspect < aspectRatio)
{
    // The new aspect ratio would make the image too wide.
    // Need to adjust the width.
    desiredWidth = (int)(desiredHeight * aspectRatio);
}

// You can now resize the image using desiredWidth and desiredHeight
//计算现有纵横比
double aspectRatio=(double)image.Width/image.Height;
//将所需值剪裁到最大值
desiredHeight=Math.Min(desiredHeight,MaxHeight);
desiredWidth=Math.Min(desiredWidth,MaxWidth);
//这是使用所需值时的纵横比。
双新宽=(双)所需宽度/所需高度;
如果(新方面>方面)
{
//新的纵横比会使图像太高。
//需要调整高度。
desiredHeight=(int)(desiredWidth/aspectRatio);
}
else if(新特性
3版模块有一个插件架构,因此默认情况下,它只提供大小调整和格式转换,以及其他一些次要功能。额外的东西是通过36+插件添加的。现在它也是免费的,您可以从下载源代码。该模块的第3版有一个插件架构,因此默认情况下它只提供大小调整和格式转换,以及其他一些次要功能。额外的东西是通过36+插件添加的。现在它也是免费的,您可以从.Hmmmm下载源代码。我倒过来了吗?嗯。我倒过来了吗?模块的第3版有一个插件架构,所以默认情况下它只提供大小调整和格式转换,以及其他一些次要功能。额外的东西是通过36+插件添加的。现在它也是免费的,您可以从下载源代码。该模块的第3版有一个插件架构,因此默认情况下它只提供大小调整和格式转换,以及其他一些次要功能。额外的东西是通过36+插件添加的。现在它也是免费的,您可以从下载源代码。