手机
当前位置:查字典教程网 >编程开发 >asp.net教程 >ASP.NET上传图片并生成可带版权信息的缩略图
ASP.NET上传图片并生成可带版权信息的缩略图
摘要:复制代码代码如下:voidPage_Load(Objectsender,EventArgse){if(!Page.IsPostBack){I...

复制代码 代码如下:

<%@PageLanguage="C#"ResponseEncoding="gb2312"%>

<%@importNamespace="System"%>

<%@importNamespace="System.IO"%>

<%@importNamespace="System.Drawing"%>

<%@importNamespace="System.Drawing.Imaging"%>

<scriptrunat="server">

voidPage_Load(Objectsender,EventArgse)

{

if(!Page.IsPostBack)

{

ImgPreview.Visible=false;

}

}

voidGetThumbnailImage(intwidth,intheight,stringstrInfo,intleft,intright)

{

stringfile="Uploads/"+uploadFile.PostedFile.FileName.Substring(uploadFile.PostedFile.FileName.LastIndexOf('')+1);

stringnewfile="Uploads/"+uploadFile.PostedFile.FileName.Substring(uploadFile.PostedFile.FileName.LastIndexOf('')+1)+".jpg";

stringstrAdd=strInfo;

System.Drawing.Imageoldimage=System.Drawing.Image.FromFile(Server.MapPath(file));

System.Drawing.ImagethumbnailImage=

oldimage.GetThumbnailImage(width,height,newSystem.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback),IntPtr.Zero);

Response.Clear();

Bitmapoutput=newBitmap(thumbnailImage);

Graphicsg=Graphics.FromImage(output);

g.DrawString(strAdd,newFont("CourierNew",14),newSolidBrush(Color.Red),left,right);

output.Save(Server.MapPath(newfile),System.Drawing.Imaging.ImageFormat.Jpeg);

Response.ContentType="image/gif";

ImgPreview.Visible=true;

ImgPreview.ImageUrl=newfile;

}

boolThumbnailCallback()

{

returntrue;

}

voidButton_Click(objectsender,EventArgse)

{

intwidth,height,left,right;

stringstrAddInfo=txtAddInfo.Text;

width=Int32.Parse(txtWidth.Text);

height=Int32.Parse(txtHeight.Text);

left=Int32.Parse(txtLeft.Text);

right=Int32.Parse(txtRight.Text);

if(!(uploadFile.PostedFile.ContentLength>0))

{

lblErrInfo.Text="没有选择文件";

}

else

{

stringpath=Server.MapPath("./Uploads/"+uploadFile.PostedFile.FileName.Substring(uploadFile.PostedFile.FileName.LastIndexOf('')+1));

if(File.Exists(path))

{

lblErrInfo.Text="已经有同名文件";

}

else

{

uploadFile.PostedFile.SaveAs(path);

GetThumbnailImage(width,height,strAddInfo,left,right);

}

}

}

</script>

<html>

<head>

</head>

<body>

<formmethod="post"enctype="multipart/form-data"runat="server">

<p>

<inputid="uploadFile"type="file"runat="server"/>

<asp:Labelid="lblErrInfo"runat="server"forecolor="Red"></asp:Label>

</p>

<p>

width:<asp:TextBoxid="txtWidth"runat="server"Width="40px">100</asp:TextBox>

height:<asp:TextBoxid="txtHeight"runat="server"Width="40px">150</asp:TextBox>

</p>

<p>

添加信息:<asp:TextBoxid="txtAddInfo"runat="server">AspxBoy.Com</asp:TextBox>

</p>

<p>

信息位置:left:<asp:TextBoxid="txtLeft"runat="server"Width="40px">10</asp:TextBox>

right:<asp:TextBoxid="txtRight"runat="server"Width="40px">135</asp:TextBox>

</p>

<p>

<inputid="button"type="button"value="上传生成所略图"onServerClick="Button_Click"runat="server"/>

</p>

<p><asp:Imageid="ImgPreview"runat="server"></asp:Image>

</p>

<>

</form>

</body>

</html>

【ASP.NET上传图片并生成可带版权信息的缩略图】相关文章:

C# 生成高质量缩略图程序—终极算法

ASP.NET上传文件的简单例子

ASP.NET弹出消息框、确认框的代码收集

调试ASP.NET应用程序的方法和技巧

ASP.net WebAPI 上传图片实例

ASP.NET中集成百度编辑器UEditor

ASP.NET 2.0 中的创建母版页

ASP.NET 页面中加添加用户控件的写法

ASP.NET创建动态缩略图的方法

ASP.NET c#生成随机数

精品推荐
分类导航