复制代码 代码如下:
<%@ Page Language="C#" ResponseEncoding="gb2312" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Imaging" %>
<script runat="server">
void Page_Load(Object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
ImgPreview.Visible = false;
}
}
void GetThumbnailImage(int width, int height, string strInfo, int left, int right)
{
string file = "Uploads/" + uploadFile.PostedFile.FileName.Substring(uploadFile.PostedFile.FileName.LastIndexOf('\\') + 1);
string newfile = "Uploads/" + uploadFile.PostedFile.FileName.Substring(uploadFile.PostedFile.FileName.LastIndexOf('\\') + 1) + ".jpg";
string strAdd = strInfo;
System.Drawing.Image oldimage = System.Drawing.Image.FromFile(Server.MapPath(file));
System.Drawing.Image thumbnailImage =
oldimage.GetThumbnailImage(width, height, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero);
Response.Clear();
Bitmap output = new Bitmap(thumbnailImage);
Graphics g = Graphics.FromImage(output);
g.DrawString(strAdd, new Font("Courier New", 14), new SolidBrush(Color.Red), left, right);
output.Save(Server.MapPath(newfile), System.Drawing.Imaging.ImageFormat.Jpeg);
Response.ContentType = "image/gif";
ImgPreview.Visible = true;
ImgPreview.ImageUrl = newfile;
}
bool ThumbnailCallback()
{
return true;
}
void Button_Click(object sender, EventArgs e)
{
int width, height, left, right;
string strAddInfo = 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
{
string path = 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 xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>上传图片并生成缩略图</title>
</head>
<body>
<form id="Form1" method="post" enctype="multipart/form-data" runat="server">
<p>
<input id="uploadFile" type="file" runat="server" />
<asp:Label ID="lblErrInfo" runat="server" ForeColor="Red"></asp:Label>
</p>
<p>
width:<asp:TextBox ID="txtWidth" runat="server" Width="40px">100</asp:TextBox>
height:<asp:TextBox ID="txtHeight" runat="server" Width="40px">150</asp:TextBox>
</p>
<p>
添加信息:<asp:TextBox ID="txtAddInfo" runat="server"> AspxBoy.Com</asp:TextBox>
</p>
<p>
信息位置:left:<asp:TextBox ID="txtLeft" runat="server" Width="40px">10</asp:TextBox>
right:<asp:TextBox ID="txtRight" runat="server" Width="40px">135</asp:TextBox>
</p>
<p>
<input id="button" type="button" value="上传生成所略图" onserverclick="Button_Click" runat="server" />
</p>
<p>
<asp:Image ID="ImgPreview" runat="server"></asp:Image>
</p>
<!-- Insert content here -->
</form>
</body>
</html>
asp.net(vbscript)上传图片并同时生成缩略图:
复制代码 代码如下:
<script language="VB" runat="server">
Sub UploadFile(sender As Object, e As EventArgs)
If FileUp.PostedFile.ContentLength = 0 Then
FileInfo.Visible = False
Exit Sub
Else
FileInfo.Visible = True
FDisplay1.Visible = True
End If
FSize.Text ="上传文件大小"+ CStr(FileUp.PostedFile.ContentLength/1024)+"KB"
FName.Text = "已上传文件名:"+FileUp.PostedFile.FileName+"<br>"+FName.Text
"写入数据库
on error resume next
dim myconn as sqlconnection
dim mycomm as sqlcommand
dim sql as string
dim id as integer
Dim image,anewimage As System.Drawing.Image
dim width,height,newwidth,newheight as integer
Dim callb As System.Drawing.Image.GetThumbnailImageAbort
myConn=New sqlconnection(ConfigurationSettings.AppSettings("数据库"))
myconn.open()
sql="insert into picture (姓名,班级,介绍,属性) values (""&request.cookies("dgxyl").values("dgxylname")&"",""&request.cookies("dgxyl").values("dgxylbj")&"",""&trim(request("TextBox1"))&"",""&request("r1")&"")"
Mycomm=New sqlcommand(sql,myconn)
mycomm.executenonquery()
myconn.close()
Dim myCommand As New SqlCommand("select top 1 id from picture order by id desc", myConn)
myCommand.Connection.Open()
Dim myReader As SqlDataReader=mycommand.executereader()
if myReader.Read() then
id=myReader("id")
end if
myconn.close()
"保存图片
FileUp.PostedFile.SaveAs( Server.MapPath("\classpic\")&cstr(id)&".jpg" )
"生成缩略图
image=System.Drawing.Image.FromFile(Server.MapPath("/classpic/"+cstr(id)+".jpg"))
width=image.Width
height=image.height
if width>height then
newwidth=250
newheight=image.height/image.Width*newwidth
else
newheight=250
newwidth=image.Width/image.height*newheight
end if
response.write("id="+cstr(id)+"width="+cstr(Width)+";height="+cstr(height)+" ")
response.write("newwidth="+cstr(newwidth)+";newheight="+cstr(newheight)+"<br>")
aNewImage=image.GetThumbnailImage(newwidth,newheight,callb,new System.IntPtr())
aNewImage.Save(Server.MapPath("/smallpic/"+cstr(id)+".jpg"))
image.Dispose()
Dim FileSplit() As String = Split( FileUp.PostedFile.FileName, "\" )
Dim FileName As String = FileSplit(FileSplit.Length-1)
Dim Exts() As String = Split( FileName, "." )
Dim Ext As String = LCase(Exts(Exts.Length-1))
FDisplay.Text = "<A Target="_blank" HREF="/classpic/"&cstr(id)&".jpg"& "">查看上传文件</A>"
FDisplay1.text="<a href="/picture/default.asp?bj="&cstr(request.cookies("dgxyl").values("dgxylbj"))&"">返回</a>"
End Sub
</script>
<SCRIPT language=JavaScript>
<!--
var requestsubmitted=false;
function guestbook_Validator(theForm)
{
//检查是否从新提交
if (requestsubmitted==true){
alert("你已经提交了留言,请等待服务器应答!");
return(false);
}
requestsubmitted=true;
return (true);
}
//-->
</SCRIPT>
<Html>
<Body BgColor=White>
<H3 align="center">请正确填写下面各项</h3>
<Hr></H3>
<Div id="FileInfo" Visible="False" runat="server">
<Asp:Label id="FSize" runat="server"/><br>
<Asp:Label id="FName" runat="server"/><br>
<Asp:Label id="FDisplay" runat="server"/>
<Asp:Label id="FDisplay1" runat="server"/>
</Div>
<Form Enctype="multipart/form-data" onsubmit="return guestbook_Validator(this)" runat="server">
上传文件
<Input Type="File" id="FileUp" runat="server" size="20"><br>
图片属性:<input type="radio" value="<%=request.cookies("dgxyl").values("dgxylbj")%>" name="R1" checked>本班<input type="radio" value="全 校" name="R1">全校(本班则只在本班显示,全校则在全校显示)<P>
图片说明:<br>
<asp:TextBox id="TextBox1" runat="server" Width="233px" Height="141px">
</asp:TextBox>
<asp:RequiredFieldValidator id="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1" ErrorMessage="请输入图片说明">
</asp:RequiredFieldValidator><br>
<Asp:button id="Upload" OnClick="UploadFile" Text="上传图片" runat="server"/>
</form>
<Hr>
<p>注意:</p>
<ol>
<li><b>严禁上传污染环境的照片,否则账号将被删除!</b></li>
<li><font color="#808000"><b>请详细填写照片说明,图片说明不详细将会被视为乱传图片,将会被删除!</b></font></li>
</ol>
</Body>
</Html>
<%@ Page Language="C#" ResponseEncoding="gb2312" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Imaging" %>
<script runat="server">
void Page_Load(Object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
ImgPreview.Visible = false;
}
}
void GetThumbnailImage(int width, int height, string strInfo, int left, int right)
{
string file = "Uploads/" + uploadFile.PostedFile.FileName.Substring(uploadFile.PostedFile.FileName.LastIndexOf('\\') + 1);
string newfile = "Uploads/" + uploadFile.PostedFile.FileName.Substring(uploadFile.PostedFile.FileName.LastIndexOf('\\') + 1) + ".jpg";
string strAdd = strInfo;
System.Drawing.Image oldimage = System.Drawing.Image.FromFile(Server.MapPath(file));
System.Drawing.Image thumbnailImage =
oldimage.GetThumbnailImage(width, height, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero);
Response.Clear();
Bitmap output = new Bitmap(thumbnailImage);
Graphics g = Graphics.FromImage(output);
g.DrawString(strAdd, new Font("Courier New", 14), new SolidBrush(Color.Red), left, right);
output.Save(Server.MapPath(newfile), System.Drawing.Imaging.ImageFormat.Jpeg);
Response.ContentType = "image/gif";
ImgPreview.Visible = true;
ImgPreview.ImageUrl = newfile;
}
bool ThumbnailCallback()
{
return true;
}
void Button_Click(object sender, EventArgs e)
{
int width, height, left, right;
string strAddInfo = 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
{
string path = 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 xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>上传图片并生成缩略图</title>
</head>
<body>
<form id="Form1" method="post" enctype="multipart/form-data" runat="server">
<p>
<input id="uploadFile" type="file" runat="server" />
<asp:Label ID="lblErrInfo" runat="server" ForeColor="Red"></asp:Label>
</p>
<p>
width:<asp:TextBox ID="txtWidth" runat="server" Width="40px">100</asp:TextBox>
height:<asp:TextBox ID="txtHeight" runat="server" Width="40px">150</asp:TextBox>
</p>
<p>
添加信息:<asp:TextBox ID="txtAddInfo" runat="server"> AspxBoy.Com</asp:TextBox>
</p>
<p>
信息位置:left:<asp:TextBox ID="txtLeft" runat="server" Width="40px">10</asp:TextBox>
right:<asp:TextBox ID="txtRight" runat="server" Width="40px">135</asp:TextBox>
</p>
<p>
<input id="button" type="button" value="上传生成所略图" onserverclick="Button_Click" runat="server" />
</p>
<p>
<asp:Image ID="ImgPreview" runat="server"></asp:Image>
</p>
<!-- Insert content here -->
</form>
</body>
</html>
asp.net(vbscript)上传图片并同时生成缩略图:
复制代码 代码如下:
<script language="VB" runat="server">
Sub UploadFile(sender As Object, e As EventArgs)
If FileUp.PostedFile.ContentLength = 0 Then
FileInfo.Visible = False
Exit Sub
Else
FileInfo.Visible = True
FDisplay1.Visible = True
End If
FSize.Text ="上传文件大小"+ CStr(FileUp.PostedFile.ContentLength/1024)+"KB"
FName.Text = "已上传文件名:"+FileUp.PostedFile.FileName+"<br>"+FName.Text
"写入数据库
on error resume next
dim myconn as sqlconnection
dim mycomm as sqlcommand
dim sql as string
dim id as integer
Dim image,anewimage As System.Drawing.Image
dim width,height,newwidth,newheight as integer
Dim callb As System.Drawing.Image.GetThumbnailImageAbort
myConn=New sqlconnection(ConfigurationSettings.AppSettings("数据库"))
myconn.open()
sql="insert into picture (姓名,班级,介绍,属性) values (""&request.cookies("dgxyl").values("dgxylname")&"",""&request.cookies("dgxyl").values("dgxylbj")&"",""&trim(request("TextBox1"))&"",""&request("r1")&"")"
Mycomm=New sqlcommand(sql,myconn)
mycomm.executenonquery()
myconn.close()
Dim myCommand As New SqlCommand("select top 1 id from picture order by id desc", myConn)
myCommand.Connection.Open()
Dim myReader As SqlDataReader=mycommand.executereader()
if myReader.Read() then
id=myReader("id")
end if
myconn.close()
"保存图片
FileUp.PostedFile.SaveAs( Server.MapPath("\classpic\")&cstr(id)&".jpg" )
"生成缩略图
image=System.Drawing.Image.FromFile(Server.MapPath("/classpic/"+cstr(id)+".jpg"))
width=image.Width
height=image.height
if width>height then
newwidth=250
newheight=image.height/image.Width*newwidth
else
newheight=250
newwidth=image.Width/image.height*newheight
end if
response.write("id="+cstr(id)+"width="+cstr(Width)+";height="+cstr(height)+" ")
response.write("newwidth="+cstr(newwidth)+";newheight="+cstr(newheight)+"<br>")
aNewImage=image.GetThumbnailImage(newwidth,newheight,callb,new System.IntPtr())
aNewImage.Save(Server.MapPath("/smallpic/"+cstr(id)+".jpg"))
image.Dispose()
Dim FileSplit() As String = Split( FileUp.PostedFile.FileName, "\" )
Dim FileName As String = FileSplit(FileSplit.Length-1)
Dim Exts() As String = Split( FileName, "." )
Dim Ext As String = LCase(Exts(Exts.Length-1))
FDisplay.Text = "<A Target="_blank" HREF="/classpic/"&cstr(id)&".jpg"& "">查看上传文件</A>"
FDisplay1.text="<a href="/picture/default.asp?bj="&cstr(request.cookies("dgxyl").values("dgxylbj"))&"">返回</a>"
End Sub
</script>
<SCRIPT language=JavaScript>
<!--
var requestsubmitted=false;
function guestbook_Validator(theForm)
{
//检查是否从新提交
if (requestsubmitted==true){
alert("你已经提交了留言,请等待服务器应答!");
return(false);
}
requestsubmitted=true;
return (true);
}
//-->
</SCRIPT>
<Html>
<Body BgColor=White>
<H3 align="center">请正确填写下面各项</h3>
<Hr></H3>
<Div id="FileInfo" Visible="False" runat="server">
<Asp:Label id="FSize" runat="server"/><br>
<Asp:Label id="FName" runat="server"/><br>
<Asp:Label id="FDisplay" runat="server"/>
<Asp:Label id="FDisplay1" runat="server"/>
</Div>
<Form Enctype="multipart/form-data" onsubmit="return guestbook_Validator(this)" runat="server">
上传文件
<Input Type="File" id="FileUp" runat="server" size="20"><br>
图片属性:<input type="radio" value="<%=request.cookies("dgxyl").values("dgxylbj")%>" name="R1" checked>本班<input type="radio" value="全 校" name="R1">全校(本班则只在本班显示,全校则在全校显示)<P>
图片说明:<br>
<asp:TextBox id="TextBox1" runat="server" Width="233px" Height="141px">
</asp:TextBox>
<asp:RequiredFieldValidator id="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1" ErrorMessage="请输入图片说明">
</asp:RequiredFieldValidator><br>
<Asp:button id="Upload" OnClick="UploadFile" Text="上传图片" runat="server"/>
</form>
<Hr>
<p>注意:</p>
<ol>
<li><b>严禁上传污染环境的照片,否则账号将被删除!</b></li>
<li><font color="#808000"><b>请详细填写照片说明,图片说明不详细将会被视为乱传图片,将会被删除!</b></font></li>
</ol>
</Body>
</Html>
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
暂无评论...
更新日志
2024年11月29日
2024年11月29日
- 凤飞飞《我们的主题曲》飞跃制作[正版原抓WAV+CUE]
- 刘嘉亮《亮情歌2》[WAV+CUE][1G]
- 红馆40·谭咏麟《歌者恋歌浓情30年演唱会》3CD[低速原抓WAV+CUE][1.8G]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[320K/MP3][193.25MB]
- 【轻音乐】曼托凡尼乐团《精选辑》2CD.1998[FLAC+CUE整轨]
- 邝美云《心中有爱》1989年香港DMIJP版1MTO东芝首版[WAV+CUE]
- 群星《情叹-发烧女声DSD》天籁女声发烧碟[WAV+CUE]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[FLAC/分轨][748.03MB]
- 理想混蛋《Origin Sessions》[320K/MP3][37.47MB]
- 公馆青少年《我其实一点都不酷》[320K/MP3][78.78MB]
- 群星《情叹-发烧男声DSD》最值得珍藏的完美男声[WAV+CUE]
- 群星《国韵飘香·贵妃醉酒HQCD黑胶王》2CD[WAV]
- 卫兰《DAUGHTER》【低速原抓WAV+CUE】
- 公馆青少年《我其实一点都不酷》[FLAC/分轨][398.22MB]
- ZWEI《迟暮的花 (Explicit)》[320K/MP3][57.16MB]