在asp.net中创建thumpnail [英] creating thumpnail in asp.net

查看:70
本文介绍了在asp.net中创建thumpnail的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个接受File的asp.net Web服务,它必须创建提供的200 X 200 pix图像文件的缩略图.请使用代码帮助我.

i want to create an asp.net webservice that will accept File and it has to create thumbnail of the image file supplied of 200 X 200 pix. please help me with the code to do so.

推荐答案

使用以下功能生成页面的缩略图.它将重新生成具有定义的高度和宽度的图像.

Use following function to generate thumbnail of the page. It will regenerate image with defined height and width.

public static void ResizeImage(string image, string Okey, string key, int width, int height, string newimagename)
    {
        System.Drawing.Image oImg = System.Drawing.Image.FromFile(HttpContext.Current.Server.MapPath("~/" + ConfigurationManager.AppSettings[Okey] + image));
 
        System.Drawing.Image oThumbNail = new System.Drawing.Bitmap(width, height);//, System.Drawing.Imaging.PixelFormat.Format24bppRgb

        System.Drawing.Graphics oGraphic = System.Drawing.Graphics.FromImage(oThumbNail);
 
        oGraphic.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
 
        //set smoothing mode to high quality
        oGraphic.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
        //set the interpolation mode
        oGraphic.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
        //set the offset mode
        oGraphic.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
 
        System.Drawing.Rectangle oRectangle = new System.Drawing.Rectangle(0, 0, width, height);
 
        oGraphic.DrawImage(oImg, oRectangle);
 
        if (newimagename == "")
        {
            if (image.Substring(image.LastIndexOf(".")) != ".png")
                oThumbNail.Save(HttpContext.Current.Server.MapPath("~/" + ConfigurationManager.AppSettings[Okey] + image), System.Drawing.Imaging.ImageFormat.Jpeg);
            else
                oThumbNail.Save(HttpContext.Current.Server.MapPath("~/" + ConfigurationManager.AppSettings[Okey] + image), System.Drawing.Imaging.ImageFormat.Png);
        }
        else
        {
            if (newimagename.Substring(newimagename.LastIndexOf(".")) != ".png")
                oThumbNail.Save(HttpContext.Current.Server.MapPath("~/" + ConfigurationManager.AppSettings[Okey] + newimagename), System.Drawing.Imaging.ImageFormat.Jpeg);
            else
                oThumbNail.Save(HttpContext.Current.Server.MapPath("~/" + ConfigurationManager.AppSettings[Okey] + newimagename), System.Drawing.Imaging.ImageFormat.Png);
        }
        oImg.Dispose();
    }


这篇关于在asp.net中创建thumpnail的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆