c#从原始图像生成缩略图

本文关键字:略图 图像 原始 | 更新日期: 2023-09-27 18:28:58

我有一个Asp.net Web表单应用程序,当上传格式的原始图像文件时

 { "cr2", "raw", "dng", "nef", "raf", "orf", "srf", "sr2", "arw", "k25", "kdc", "dcr","mos",
        "pnx", "crw", "mrw", "pef" , "mef" , "rw2","a7","a7r"}

如何从原始图像生成缩略图?

c#从原始图像生成缩略图

您可以使用在.net应用程序上运行的dcraw.exe应用程序。您可以在链接中下载它。

首先将原始图像保存在本地磁盘中,并使用代码:

string dcrawPath = "dcraw.exe";
ProcessStartInfo startInfo = new ProcessStartInfo();
string inputImagePath= "input Raw Image Path/";
string outputImagePath = "output Raw Image Path/";
startInfo.RedirectStandardError = true;
startInfo.RedirectStandardOutput = true;
startInfo.CreateNoWindow = true;
startInfo.UseShellExecute = false;
startInfo.FileName = dcrawPath;
string commandArg1 = string.Format("'"{0}'"", outputImagePath);
string commandArg2 = string.Format("'"{0}'"", inputImagePath);
startInfo.Arguments = "-u ";
startInfo.Arguments += commandArg1;
startInfo.Arguments += " -e ";
startInfo.Arguments += commandArg2;
startInfo.Arguments += " -T";
using (Process exeProcess = Process.Start(startInfo))
  {
   exeProcess.WaitForExit();
   string stdout = exeProcess.StandardOutput.ReadToEnd();
   string stderr = exeProcess.StandardError.ReadToEnd();
   Console.WriteLine("Exit code : {0}", exeProcess.ExitCode);
  }

将原始图像放入inputImagePath变量

您可以在outputImagePath变量中找到图像

试试GDPicture.NET组件。它支持不同的RAW格式,易于使用,但不是免费的。要生成缩略图,请使用GdPictureImaging类的CreateThumbnailCreateThumbnailHQ方法:

  using (var imaging = new GdPictureImaging())
  {
    int pictureId = imaging.CreateGdPictureImageFromFile(filepath);
    if (pictureId == 0)
    {
      MessageBox.Show("Error: " + imaging.GetStat().ToString());
      return;
    }
    int thumbnailImgId = imaging.CreateThumbnail(pictureId, 20, 20);
    imaging.SaveAsPNG(thumbnailImgId, "thumbnail.png");
    imaging.ReleaseGdPictureImage(thumbnailImgId);
    imaging.ReleaseGdPictureImage(pictureId);
  }