これは、複数ページの tiff ファイルを 1 ページの jpeg に変換するための asp.net ソースです。
以前はMemoryStreamクラスを使用してからjpegに変換しました。
これは、Windows 2005、IIS6、Visual Studio 2008、および .NET Framework 2.0 にあります。
MemoryStream ms = null;
Image SrcImg = null;
Image returnImage = null;
try
{
SrcImg = Image.FromFile(@'d:\\test.tif');
ms = new MemoryStream();
FrameDimension FrDim = new FrameDimension(SrcImg.FrameDimensionsList[0]);
SrcImg.SelectActiveFrame(FrDim, 17); // 17 page...
SrcImg.Save(ms, ImageFormat.Tiff);
// Prevent using images internal thumbnail
SrcImg.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
SrcImg.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
//Save Aspect Ratio
if (SrcImg.Width <= ImgWidth) ImgWidth = SrcImg.Width;
int NewHeight = SrcImg.Height * ImgWidth / SrcImg.Width;
if (NewHeight > ImgHeight)
{
// Resize with height instead
ImgWidth = SrcImg.Width * ImgHeight / SrcImg.Height;
NewHeight = ImgHeight;
}
returnImage = Image.FromStream(ms).GetThumbnailImage(ImgWidth, NewHeight, null, IntPtr.Zero); }
ただし、このコードは Windows 2008、IIS7、Visual Studio 2010、および .NET Framework 4.0 で問題なく動作します。
エラーは「SelectActiveFrame」文を消去します。
サンプルの tiff ファイルを次に示します。 [マウスの右クリック - 「test.tif」として保存]
どうしたの?または良い解決策はありますか?