我有一张图片,一个textbox,一个button,我想在textbox里输入字符,然后按button确定,图片上就可以显示我已输入的字符?
其实我最终想解决的是在一个Datalist里面有很多图片,我按下button就可以在Datalist添加指定的图片,图片上面有textbox的文字! 如果可以解决到第一个问题,我都很高兴了!thanks。
其实我最终想解决的是在一个Datalist里面有很多图片,我按下button就可以在Datalist添加指定的图片,图片上面有textbox的文字! 如果可以解决到第一个问题,我都很高兴了!thanks。
解决方案 »
- 大家帮看下题目的意思
- 请问下webservice与WCF有什么区别
- 怎么让KinSlideshow()显示在浮动层下面?
- 怎么样在三层架构中实现单态啊.我是初学者不是很明白类静态.
- 为什么租的好多.net的虚拟主机,一放上程序去就出来“应用程序中的服务器错误”
- 如何把文件夹下的图片显示在DATAGRID中?
- 在页面中现实数据库的一个字段(大量的文本),用什么最好??
- 请问如果有 10 万 条数据 该怎么查询,我一查询就出错
- 怎样定义id为6位数:000001,并且+1时为:000002,是(C#语言),谢谢.
- 已成功与服务器建立连接,但是在登录前的握手期间发生错误。 (provider: TCP Provider, error: 0 - 远程主机强迫关闭了一个现有的
- 请问ASPNET中如何修改XML中<?xml-stylesheet type='text/xsl' href='default.xslt'?>元素的属性值??
- 关于rational XDE for .net的问题?
Graphics g = Graphics.FromImage(image);
g.DrawImage(image, 0, 0, image.Width, image.Height);
Font f = new Font("Verdana", 32);
Brush b = new SolidBrush(Color.White);
string addText = AddText.Value.Trim();//AddText is your textbox.
g.DrawString(addText, f, b, 10, 10);
g.Dispose();
关键代码: try{
mPath=Server.MapPath("..\\db\\upImg");
string tempPath=Server.MapPath("..\\db\\")+newImgName+"."+ImgType;
string SaveImagePath=mPath+"\\"+newImgName+"."+ImgType;
path.PostedFile.SaveAs(tempPath); Err.Text=Common.Alert("图片 "+ImgName+" 成功上传!");
//---------------------------添加文字--------------
if(ImgType.ToLower()=="jpg")
//只支持jpg格式的图片 {
System.Drawing.Image image = System.Drawing.Image.FromFile(tempPath);
Graphics g = Graphics.FromImage(image);
g.DrawImage(image, 0, 0, image.Width, image.Height); Font t = new Font("Georgia",TopSize);
Font b = new Font("Georgia",BottomSize); Brush top,bottom;
switch (TopColor)
{
case "Red":
top=new SolidBrush(Color.Red);
break;
case "Black":
top=new SolidBrush(Color.Black);
break;
case "White":
top=new SolidBrush(Color.White);
break;
case "Yellow":
top=new SolidBrush(Color.Yellow);
break;
case "Blue":
top=new SolidBrush(Color.Blue);
break;
case "Green":
top=new SolidBrush(Color.Green);
break;
case "Gray":
top=new SolidBrush(Color.Gray);
break;
default:
top=new SolidBrush(Color.Red);
break;
}
switch (BottomColor)
{
case "Red":
bottom=new SolidBrush(Color.Red);
break;
case "Black":
bottom=new SolidBrush(Color.Black);
break;
case "White":
bottom=new SolidBrush(Color.White);
break;
case "Yellow":
bottom=new SolidBrush(Color.Yellow);
break;
case "Blue":
bottom=new SolidBrush(Color.Blue);
break;
case "Green":
bottom=new SolidBrush(Color.Green);
break;
case "Gray":
bottom=new SolidBrush(Color.Gray);
break;
default:
bottom=new SolidBrush(Color.Red);
break;
}
string addText = "出处: http://y24y.7i24.com ("+DateTime.Now.ToString("yyyy.MM.dd")+")";
//右下角文字
g.DrawString(About.Text.Trim(), t, top, 1, 1);
//左上角文字
if(BottomSize==14)
{
g.DrawString(addText, b, bottom, image.Width-410, image.Height-25);
}
else if(BottomSize==12)
{
g.DrawString(addText, b, bottom, image.Width-350, image.Height-20);
}
else
{
g.DrawString(addText, b, bottom, image.Width-300, image.Height-18);
}
g.Dispose();
string newPath = SaveImagePath; image.Save(newPath);
image.Dispose();
}
//-----------------------------------------
else
{
path.PostedFile.SaveAs(SaveImagePath);
}
//删除临时文件
if(File.Exists(tempPath))
{
File.Delete(tempPath);
}
}
catch(Exception ex){ Response.Write(Common.Alert("Error: 此图片有问题,无法上传")); }
private void Btn_Upload_Click(object sender, System.EventArgs e)
{
if(UploadFile.PostedFile.FileName.Trim()!="")
{ //上传文件 string extension = Path.GetExtension(UploadFile.PostedFile.FileName).ToUpper(); string fileName = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString(); string path = Server.MapPath(".") + "/UploadFile/" + fileName + extension; UploadFile.PostedFile.SaveAs(path); //加文字水印,注意,这里的代码和以下加图片水印的代码不能共存 System.Drawing.Image image = System.Drawing.Image.FromFile(path); Graphics g = Graphics.FromImage(image); g.DrawImage(image, 0, 0, image.Width, image.Height); Font f = new Font("Verdana", 32); Brush b = new SolidBrush(Color.White); string addText = AddText.Value.Trim(); g.DrawString(addText, f, b, 10, 10); g.Dispose(); //加图片水印 System.Drawing.Image image = System.Drawing.Image.FromFile(path); System.Drawing.Image copyImage = System.Drawing.Image.FromFile( Server.MapPath(".") + "/Alex.gif"); Graphics g = Graphics.FromImage(image); g.DrawImage(copyImage, new Rectangle(image.Width-copyImage.Width, image.Height-copyImage.Height, copyImage.Width, copyImage.Height), 0, 0, copyImage.Width, copyImage.Height, GraphicsUnit.Pixel); g.Dispose(); //保存加水印过后的图片,删除原始图片 string newPath = Server.MapPath(".") + "/UploadFile/" + fileName + "_new" + extension; image.Save(newPath); image.Dispose(); if(File.Exists(path)) { File.Delete(path); } Response.Redirect(newPath); } }
WebForm1.aspx
------------------------------------------------------------------------------
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="CS_WebTest.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<asp:textbox id="txb_Test" Runat="server"></asp:textbox><asp:button id="btn_Test" Runat="server" Text="提交"></asp:button><asp:image id="img_Test" Runat="server"></asp:image></form>
</body>
</HTML>
------------------------------------------------------------------------------
下一贴
-----------------------------------------------------------------------------------
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;namespace CS_WebTest
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox txb_Test;
protected System.Web.UI.WebControls.Image img_Test;
protected System.Web.UI.WebControls.Button btn_Test;
private void Page_Load(object sender, System.EventArgs e)
{
if (this.IsPostBack == false)
{ }
} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.btn_Test.Click += new System.EventHandler(this.btn_Test_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void btn_Test_Click(object sender, System.EventArgs e)
{
string sCode = txb_Test.Text;
Bitmap oBmp = new Bitmap(40,20);
Graphics oG = Graphics.FromImage(oBmp);
oG.Clear(Color.White);
oG.DrawString(sCode,new Font("宋体",12,FontStyle.Bold),new HatchBrush(HatchStyle.LargeConfetti,
Color.FromArgb(200,Color.Blue),Color.FromArgb(200,Color.LightBlue)),0,5);
Response.Write(Server.MapPath("") + @"\" + txb_Test.Text + ".jpg");
try
{
oBmp.Save(Server.MapPath("") + @"\" + txb_Test.Text + ".jpg",System.Drawing.Imaging.ImageFormat.Jpeg);
img_Test.ImageUrl = txb_Test.Text + ".jpg";
}
catch{}
}
}
}-----------------------------------------------------------------------------------