前几天在论坛上求的一段代码当时没有说清语言,那们大哥帮我翻一下。
下面的代码在运行的时候还有一点错。
<%@ Page Language="c#" Debug="true" Trace="true"%>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Imaging" %>
<html>
<script runat =server>
void UploadBtn_Click(Object sender, EventArgs e) {
String filename;
String filename1;
String[] filename2;
int q;
filename=UploadFile.PostedFile.FileName ;
filename2=filename.Split(new Char[] {'\\'});
q=filename2.GetUpperBound(0);
filename1=filename2[q];
dis.Text="上传文件名:"+filename1+"<br/>";
UploadFile.PostedFile.SaveAs(Server.MapPath(filename1));
ImageEditor.Visible = true;
dis.Text+="文件大小:"+UploadFile.PostedFile.ContentLength+"字节数";
Image1.Src=filename1;
}
void UpdateBtn_Click(Object sender, EventArgs e) {
String filename1;
filename1=Image1.Src;
System.Drawing.Image image = System.Drawing.Image.FromFile(Server.MapPath(filename1));
System.Drawing.Image newimage = new Bitmap(image.Width, image.Height, PixelFormat.Format32bppRGB);
Graphics g = Graphics.FromImage(newimage);
g.DrawImage(image,0,0,image.Width,image.Height);
Font f = new Font(FontType.SelectedItem.Text, Int32.Parse(FontSize.SelectedItem.Text));
Brush b = new SolidBrush(Color.Red);
g.DrawString(Caption.Text, f, b, 10, 140);
g.Dispose();
System.Drawing.Image thumbImage = newimage.GetThumbnailImage(Int32.Parse(Width.Text),Int32.Parse(Height.Text),null,0);
image.Dispose();
thumbImage.Save(Server.MapPath(filename1), ImageFormat.JPEG);
Image1.Src=filename1;
Caption.Text=""; }</script><body>
<asp:label id="dis" runat=server/>
<form enctype="multipart/form-data" runat=server><h3>Select File To Upload: <input id="UploadFile" type=file runat=server><asp:button Text="Upload Me!" OnClick="UploadBtn_Click" runat=server/><hr><asp:panel id="ImageEditor" Visible=false runat=server><img ID="Image1" src="" runat="server"/><h3>
Image Width: <asp:textbox id="Width" runat=server/>Image Height: <asp:textbox id="Height" runat=server/> <br/>Text Caption: <asp:textbox id="Caption" runat=server/>Caption Size: <asp:dropdownlist id="FontSize" runat=server>
<asp:listitem>14</asp:listitem>
<asp:listitem>18</asp:listitem>
<asp:listitem>26</asp:listitem>
<asp:listitem>36</asp:listitem>
<asp:listitem>48</asp:listitem>
<asp:listitem>62</asp:listitem>
</asp:dropdownlist>
Caption Font: <asp:dropdownlist id="FontType" runat=server>
<asp:listitem>黑体</asp:listitem>
<asp:listitem>仿宋</asp:listitem>
<asp:listitem>隶书</asp:listitem>
<asp:listitem>楷书</asp:listitem>
<asp:listitem>方正姚体</asp:listitem>
<asp:listitem>华文彩云</asp:listitem>
</asp:dropdownlist><asp:button Text="Update Image" OnClick="UpdateBtn_Click" runat=server/></h3>
</asp:panel></form></body>
</html>
下面的代码在运行的时候还有一点错。
<%@ Page Language="c#" Debug="true" Trace="true"%>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Imaging" %>
<html>
<script runat =server>
void UploadBtn_Click(Object sender, EventArgs e) {
String filename;
String filename1;
String[] filename2;
int q;
filename=UploadFile.PostedFile.FileName ;
filename2=filename.Split(new Char[] {'\\'});
q=filename2.GetUpperBound(0);
filename1=filename2[q];
dis.Text="上传文件名:"+filename1+"<br/>";
UploadFile.PostedFile.SaveAs(Server.MapPath(filename1));
ImageEditor.Visible = true;
dis.Text+="文件大小:"+UploadFile.PostedFile.ContentLength+"字节数";
Image1.Src=filename1;
}
void UpdateBtn_Click(Object sender, EventArgs e) {
String filename1;
filename1=Image1.Src;
System.Drawing.Image image = System.Drawing.Image.FromFile(Server.MapPath(filename1));
System.Drawing.Image newimage = new Bitmap(image.Width, image.Height, PixelFormat.Format32bppRGB);
Graphics g = Graphics.FromImage(newimage);
g.DrawImage(image,0,0,image.Width,image.Height);
Font f = new Font(FontType.SelectedItem.Text, Int32.Parse(FontSize.SelectedItem.Text));
Brush b = new SolidBrush(Color.Red);
g.DrawString(Caption.Text, f, b, 10, 140);
g.Dispose();
System.Drawing.Image thumbImage = newimage.GetThumbnailImage(Int32.Parse(Width.Text),Int32.Parse(Height.Text),null,0);
image.Dispose();
thumbImage.Save(Server.MapPath(filename1), ImageFormat.JPEG);
Image1.Src=filename1;
Caption.Text=""; }</script><body>
<asp:label id="dis" runat=server/>
<form enctype="multipart/form-data" runat=server><h3>Select File To Upload: <input id="UploadFile" type=file runat=server><asp:button Text="Upload Me!" OnClick="UploadBtn_Click" runat=server/><hr><asp:panel id="ImageEditor" Visible=false runat=server><img ID="Image1" src="" runat="server"/><h3>
Image Width: <asp:textbox id="Width" runat=server/>Image Height: <asp:textbox id="Height" runat=server/> <br/>Text Caption: <asp:textbox id="Caption" runat=server/>Caption Size: <asp:dropdownlist id="FontSize" runat=server>
<asp:listitem>14</asp:listitem>
<asp:listitem>18</asp:listitem>
<asp:listitem>26</asp:listitem>
<asp:listitem>36</asp:listitem>
<asp:listitem>48</asp:listitem>
<asp:listitem>62</asp:listitem>
</asp:dropdownlist>
Caption Font: <asp:dropdownlist id="FontType" runat=server>
<asp:listitem>黑体</asp:listitem>
<asp:listitem>仿宋</asp:listitem>
<asp:listitem>隶书</asp:listitem>
<asp:listitem>楷书</asp:listitem>
<asp:listitem>方正姚体</asp:listitem>
<asp:listitem>华文彩云</asp:listitem>
</asp:dropdownlist><asp:button Text="Update Image" OnClick="UpdateBtn_Click" runat=server/></h3>
</asp:panel></form></body>
</html>
解决方案 »
- 问个服务器安全的问题
- eWebEdit编辑器问题
- ASP.NET Cookie值取不到
- 在DataTable中如何建牵引????
- 数据库连接问题,菜鸟求大侠
- 怪了,怎么在纯html页中不能使用include,在asp.net中却能用???????请老师们指点。
- Calendar美化问题
- Microsoft Visual Studio 2005 Professional DVD版本(bt下载)
- 举手之劳的问题:vb.net中如何返回地址
- 怎样在ASP.net中实现屏蔽IE的刷新按钮?
- 打包的问题,有高手没有,用的vs2003,C#写的Web程序,用到了水晶报表10.0,打包安装过后水晶报表没有出来!
- 页面乱码问题..请教..
Dim filename As String
Dim filename1 As String
Dim filename2 As String()
Dim q As Integer
filename = UploadFile.PostedFile.FileName
filename2 = filename.Split(New Char() {"\"C})
q = filename2.GetUpperBound(0)
filename1 = filename2(q)
dis.Text = "上传文件名:" + filename1 + "<br/>"
UploadFile.PostedFile.SaveAs(Server.MapPath(filename1))
ImageEditor.Visible = True
dis.Text += "文件大小:" + UploadFile.PostedFile.ContentLength + "字节数"
Image1.Src = filename1
End Sub Sub UpdateBtn_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim filename1 As String
filename1 = Image1.Src
Dim image As System.Drawing.Image = System.Drawing.Image.FromFile(Server.MapPath(filename1))
Dim newimage As System.Drawing.Image = New Bitmap(image.Width, image.Height, PixelFormat.Format32bppRGB)
Dim g As Graphics = Graphics.FromImage(newimage)
g.DrawImage(image, 0, 0, image.Width, image.Height)
Dim f As Font = New Font(FontType.SelectedItem.Text, Int32.Parse(FontSize.SelectedItem.Text))
Dim b As Brush = New SolidBrush(Color.Red)
g.DrawString(Caption.Text, f, b, 10, 140)
g.Dispose
Dim thumbImage As System.Drawing.Image = newimage.GetThumbnailImage(Int32.Parse(Width.Text), Int32.Parse(Height.Text), Nothing, 0)
image.Dispose
thumbImage.Save(Server.MapPath(filename1), ImageFormat.JPEG)
Image1.Src = filename1
Caption.Text = ""
End Sub