"Parrot" <Pa****@discuss ions.microsoft. com> wrote in message
news:53******** *************** ***********@mic rosoft.com...
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.
"Brock Allen" wrote:
Check out Bitmap.GetThumb nailImage
My first trys using GetThumbnailIma ge were very ugly, but this makes images
that look just fine:
-Fred
using System;
using System.Data;
using System.Configur ation;
using System.Web;
using System.Web.Secu rity;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.W ebControls.WebP arts;
using System.Web.UI.H tmlControls;
using System.IO;
using System.Drawing;
/// <summary>
/// Summary description for makeThumbnail
/// </summary>
public class makeThumbnail
{
public makeThumbnail(s tring parmFileIn, out int rc)
{
rc = 0;
string filePathSourceF ile = HttpContext.Cur rent.Server.Map Path("~/images/");
string filePathDestFil e =
HttpContext.Cur rent.Server.Map Path("~/thumbnails/");
string fullSourceFile = filePathSourceF ile + parmFileIn;
//string currentImageFil e;
//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.Hei ght;
wx = sourceImage.Wid th;
// calc the thumbnail Width and Height: -scale to max with
if (sourceImage.Wi dth > sourceImage.Hei ght) // 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.Get ThumbnailImage( thumbnailWidth, thumbnailHeight , new
System.Drawing. Image.GetThumbn ailImageAbort(T humbnailCallbac k),
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(imageStrea m, System.Drawing. Imaging.ImageFo rmat.Jpeg);
string outfile = filePathDestFil e + parmFileIn;
try
{
thumbnailImage. Save(outfile);
rc = 77;
}
catch (Exception e)
{
rc = 27;
string dummy = e.ToString();
return;
}
}
/// <summary>
/// </summary>
/// <returns>true </returns>
public bool ThumbnailCallba ck()
{
return true;
}
}