Topbar
Topbar
Sign in
|
Join
|
Client Center
Home
Products
Client Center
Contact
Purchase
Support forums
»
Products
»
Ajax Uploader
»
Re: image thumbnail
Re: image thumbnail
08-11-2009, 3:41 AM
cutechat
Joined on 07-22-2004
Posts 2,332
Re: image thumbnail
Reply
Quote
Hi,
You can try this code :
private
void
GenerateThumbnail(
string
filepath,
string
thumbnailPath)
{
byte
[] data;
using
(FileStream fs=
new
FileStream(filepath,FileMode.Open,FileAccess.Read,FileShare.Read))
{
data=
new
byte
[fs.Length];
fs.Read(data,0,data.Length);
}
using
(System.Drawing.Image img = System.Drawing.Image.FromStream(
new
MemoryStream(data)))
{
double
size=128d;
double
scale = Math.Min( size/img.Width, size/img.Height );
int
w = (
int
)(img.Width * scale);
int
h = (
int
)(img.Height * scale);
using
(System.Drawing.Image thumb=
new
System.Drawing.Bitmap(w,h,System.Drawing.Imaging.PixelFormat.Format24bppRgb))
{
using
(System.Drawing.Graphics g=System.Drawing.Graphics.FromImage(thumb))
{
g.InterpolationMode=System.Drawing.Drawing2D.InterpolationMode.High;
g.DrawImage(img
,
new
System.Drawing.Rectangle(-1, -1, w+2, h+2)
,
new
System.Drawing.Rectangle(0, 0, img.Width, img.Height)
, System.Drawing.GraphicsUnit.Pixel);
thumb.Save(thumbnailPath);
}
}
}
}
Regards,
Terry
View Complete Thread