asp.net| upload | upload pictures | thumbnail private void Btnuploadpicture_click (object sender, System.EventArgs e)
{
Check that the upload file is in a valid format
if (this. UploadFile.PostedFile.ContentType.ToLower (). IndexOf ("image") < 0)
{
Response.Write ("Upload picture format is invalid!") ");
Return
}
int owidth = Oimage.width; Width of original artwork
int oheight = Oimage.height; Height of original artwork
int twidth = 100; Set the initial width of the thumbnail
int theight = 100; Set the initial height of the thumbnail
Calculate the width and height of the thumbnail proportionally
if (owidth >= oheight)
{
Theight = (int) Math.floor (convert.todouble (oheight) * (convert.todouble (twidth)/convert.todouble (oWidth)));
}
Else
{
Twidth = (int) Math.floor (convert.todouble (owidth) * (convert.todouble (theight)/convert.todouble (oHeight)));
}
Generate thumbnail artwork
Bitmap timage = new Bitmap (twidth,theight);
Graphics g = graphics.fromimage (timage);
G.interpolationmode = System.Drawing.Drawing2D.InterpolationMode.High; Set high quality interpolation method
G.smoothingmode = system.drawing.drawing2d.smoothingmode.highquality;//Set high quality, low speed rendering smooth degree
G.clear (color.transparent); Empty the canvas and fill with a transparent background color
G.drawimage (oimage,new Rectangle (0,0,twidth,theight), New Rectangle (0,0,owidth,oheight), graphicsunit.pixel);
String ofullname = Server.MapPath (".") + "/" + "O" + DateTime.Now.ToShortDateString (). Replace ("-", "") + DateTime.Now.Hour.ToString () + DateTime.Now.Minute.ToString () + DateTime.Now.Second.ToString () + DateTime.Now.Millisecond.ToString () + ". jpg"; Save the physical path of the original artwork
String tfullname = Server.MapPath (".") + "/" + "T" + DateTime.Now.ToShortDateString (). Replace ("-", "") + DateTime.Now.Hour.ToString () + DateTime.Now.Minute.ToString () + DateTime.Now.Second.ToString () + DateTime.Now.Millisecond.ToString () + ". jpg"; Save the physical path of the thumbnail
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.