从数据库中图片的流文件,显示在 image 控件里面要怎么做。谢谢。谢谢
解决方案 »
- 关于Gridview绑定excel问题
- 大家好,请问怎样生成流水号?多线程的
- TextBox事件(即填写完指定textbox后,带出其余信息)
- 无法在web服务器上启动调节器试。web服务器未找到请求的资源
- 急!!!!在线等,问题解决就给分,还是刚才的那个问题...怎么没人回答了?就这么点分了,还请大家帮忙啊
- 挑战高手,.NET邮件发不了...
- 救助:在学多层开发模式遇到的种种问题
- TextBox问题?请大家帮帮我!
- 100分!!!,求助!我使用了sqldatareader ,当这个网页打开后,刷新20次,马上出现连接池满,已达到最大连接数,这是我的代码,请高手
- 怎么调出新的页面?
- 在asp.net中如何调用flash?
- ●在网页上 将Word转换成Html
Try
Dim fs As IO.FileStream
Dim bw As IO.BinaryWriter
Dim conn As New SqlClient.SqlConnection("server=(local);database=tempdb;uid=sa;pwd=;")
Dim logoCMD As New SqlClient.SqlCommand("select id,photo from testPhoto", conn)
Dim bufferSize As Integer = 100
Dim outbyte(bufferSize - 1) As Byte
Dim retval As Long
Dim startIndex As Long = 0
Dim FN as String Dim pub_id As String = "" conn.Open()
Dim myReader As SqlClient.SqlDataReader = logoCMD.ExecuteReader(CommandBehavior.SequentialAccess) Do While myReader.Read()
pub_id = myReader("id")
FN="image" & pub_id & ".bmp"
fs = New IO.FileStream(FN, IO.FileMode.OpenOrCreate, IO.FileAccess.Write)
bw = New IO.BinaryWriter(fs) startIndex = 0
retval = myReader.GetBytes(1, startIndex, outbyte, 0, bufferSize)
Do While retval = bufferSize
bw.Write(outbyte)
bw.Flush()
startIndex += bufferSize
retval = myReader.GetBytes(1, startIndex, outbyte, 0, bufferSize)
Loop bw.Write(outbyte, 0, retval - 1)
bw.Flush() bw.Close()
fs.Close()
Loop
conn.Close()
myReader.Close()
Catch ex As Exception
........
End Try End Sub
<asp:Image ID="imgCtrl" runat="server"></asp:Image>
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;namespace Blast
{ public class editpic : PageBase
{
protected System.Web.UI.WebControls.Image imgCtrl;
protected System.Web.UI.WebControls.TextBox tbTitle;
protected System.Web.UI.WebControls.TextBox tbDescription;
protected System.Web.UI.WebControls.Label lbTitle;
protected System.Web.UI.WebControls.Button SaveButton; private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
// 从数据库中载入图片的属性
int picid = Convert.ToInt32(Request["id"]);
string title, description;
Globals.GetPicInfo(picid, out title, out description); // 设置要修改的字段
tbTitle.Text = title;
tbDescription.Text = description; // 设置由genimage产生的图片
imgCtrl.ImageUrl = "genimage.ashx?thumbnail=yes&id=" + picid;
}
} #region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{ InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.SaveButton.Click += new System.EventHandler(this.SaveButton_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void SaveButton_Click(object sender, System.EventArgs e)
{
// 更新数据库
int picid = Convert.ToInt32(Request["id"]);
Globals.UpdatePicInfo(picid, tbTitle.Text, tbDescription.Text);
Response.Redirect("viewpic.aspx?id="+picid);
}
}
}
1 显示图片的页面,调用取图片的页面
我在页面里的DataGrid放了一个图片,用了一个连接到另一个页面取图片
<asp:Image id=Imagebutton1 runat="server" ImageUrl='<%# "BookCover.aspx?ImageID="+DataBinder.Eval(Container,"DataItem.BookGuid")%>'></asp:Image>BookCover.aspx 读取图片的页面string str=System.Configuration.ConfigurationSettings.AppSettings["cn"];
SqlConnection cn=new SqlConnection(str);
SqlCommand cmd=new SqlCommand();
cmd.CommandText="select Cover from Books where BookGuid='"+this.Request["ImageID"]+"'";
cmd.Connection=cn;
cn.Open();
this.Response.ContentType="image/*";
SqlDataReader dr=cmd.ExecuteReader();
while(dr.Read())
{
this.Response.BinaryWrite((byte[])dr["Cover"]);
}
cn.Close();
代码是写在private void Page_Load(object sender, System.EventArgs e)里的