我正在使用.NET(4.5)MVC(4.0)C#(5.0)开发应用程序.我想从我已经拥有的图像生成图像缩略图.现在的要求是它应该从图像中心生成最大方形部分的缩略图而不拉伸除了图像之外的整个图像是方形尺寸.
根据示例我的原始图像大小:578x700我想生成占位符大小的缩略图:200x150,185x138,140x140,89x66,80x80,45x45,28x28
我创建了我的下面的代码,但没有得到确切的结果.这是我生成缩略图的核心方法
public string GenerateThumbnailFromImage(string imageFilePath, int thumbWidth, int thumbHeight)
{
try
{
//Check if file exist
if (File.Exists(imageFilePath))
{
//bool preserveAspectRatio = true;
string oldFilePath = imageFilePath;
string folderPath = Path.GetDirectoryName(imageFilePath);
string filename = Path.GetFileNameWithoutExtension(imageFilePath);
//Rename file with thumbnail size
filename = filename + "_" + thumbWidth.ToString() + Path.GetExtension(imageFilePath);
imageFilePath = Path.Combine(folderPath, filename);
using (Image image = Image.FromFile(oldFilePath))
{
decimal originalWidth = image.Width;
decimal originalHeight = image.Height;
decimal requiredThumbWidth = thumbWidth;
decimal requiredThumbHeight = thumbHeight;
decimal startXPosition = …Run Code Online (Sandbox Code Playgroud)