Parrot said:
Brock;
Thanks for yur reply. I tried the Get ThumbnailImage function but the
resulting image is fuzzy. I reduced a 1360 X 2048 image to 272 X 408 and
the
edges are blurry. I need something that gives me a better resolution.
My first trys using GetThumbnailImage were very ugly, but this makes images
that look just fine:
-Fred
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Drawing;
/// <summary>
/// Summary description for makeThumbnail
/// </summary>
public class makeThumbnail
{
public makeThumbnail(string parmFileIn, out int rc)
{
rc = 0;
string filePathSourceFile = HttpContext.Current.Server.MapPath("~/images/");
string filePathDestFile =
HttpContext.Current.Server.MapPath("~/thumbnails/");
string fullSourceFile = filePathSourceFile + parmFileIn;
//string currentImageFile;
//string thumbnailFile;
int thumbnailHeight;
int thumbnailWidth;
int maxThumbSize = 150;
//int minThumbSize = 120; // 4 x 6 ratio
double hx; double wx;
// create an image object, using the filename we just retrieved
System.Drawing.Image sourceImage =
System.Drawing.Image.FromFile(fullSourceFile);
hx = sourceImage.Height;
wx = sourceImage.Width;
// calc the thumbnail Width and Height: -scale to max with
if (sourceImage.Width > sourceImage.Height) // landscape: width is fixed,
scale height:
{
thumbnailWidth = maxThumbSize;
//thumbnailHeight = minThumbSize;
thumbnailHeight = Convert.ToInt32((hx / wx) * thumbnailWidth);
}
else // portrait: height is fixed at max, scale width:
{
thumbnailHeight = maxThumbSize;
thumbnailWidth = Convert.ToInt32((wx / hx) * thumbnailHeight);
}
System.Drawing.Image thumbnailImage =
sourceImage.GetThumbnailImage(thumbnailWidth, thumbnailHeight, new
System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback),
IntPtr.Zero);
// make a memory stream to work with the image bytes
MemoryStream imageStream = new MemoryStream();
// put the image into the memory stream
thumbnailImage.Save(imageStream, System.Drawing.Imaging.ImageFormat.Jpeg);
string outfile = filePathDestFile + parmFileIn;
try
{
thumbnailImage.Save(outfile);
rc = 77;
}
catch (Exception e)
{
rc = 27;
string dummy = e.ToString();
return;
}
}
/// <summary>
/// </summary>
/// <returns>true</returns>
public bool ThumbnailCallback()
{
return true;
}
}