WEB(C#),我把图片放在数据库的IMAGE字段,显示图片用IMAGE控件,怎么实现保存图片到数据库后,能缩略显示。求代码 我快死了。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 if(this.File1.Value!=""||this.File1.Value!=null){ try { HttpPostedFile UpFile = this.File1.PostedFile; FileLength = UpFile.ContentLength; if (FileLength != 0) { Byte[] FileByteArray = new Byte[FileLength]; Stream StreamObject = UpFile.InputStream; StreamObject.Read(FileByteArray,0,FileLength); dr["c_image"]=FileByteArray; } } catch { Response.Write("<script defer>alert(\"图片格式不正确!\")</script>"); return; }}读取:try { byte[] bys = (byte[])row["c_image"]; if(bys.Length > 100) Response.OutputStream.Write(bys, 0, bys.Length); Response.Write("没有图片!"); }catch { Response.Write("没有图片!"); return; } public string ResizeBitmap(string strFileName,int nWidth,int nHeight,int maxWidth) { //将原始图片缩放为指定大小的图片 System.Drawing.Bitmap b = new System.Drawing.Bitmap(Server.MapPath(strFileName)); if(b.Width > maxWidth) { if(nHeight < 1) nHeight = b.Height; Bitmap result = new Bitmap(nWidth,nHeight); Graphics g = Graphics.FromImage((System.Drawing.Image)result); g.DrawImage(b,0,0,nWidth,nHeight); int index=strFileName.LastIndexOf("/"); string strForeside=""; if(index>0) strForeside=strFileName.Substring(0,index+1); strFileName = strForeside+"Temp"+strFileName.Substring(strFileName.Length-4); result.Save(Server.MapPath(strFileName)); result.Dispose(); g.Dispose(); } b.Dispose(); return strFileName; } 怎么通过网页的下载链接直接打开.dwg文件 关于上传控件NeatUpload的一些问题 C#套接字编程 求vs2005 winfrom datagridview的例子 想求一下关于三层架构之间怎么样连接起来的问题 紧急问题,加分............ Silverlight能用在directx表面吗? c# label 的size问题 asp.net中将oracle数据库数据导出为xml文件,在将xml文件导入回oracle数据库. Remoting 实现查询 combobox的SelectedIndexChanged事件,把数据库中的某列的值,加到combobox的. 简单一个"为什么"
{
try
{
HttpPostedFile UpFile = this.File1.PostedFile;
FileLength = UpFile.ContentLength;
if (FileLength != 0)
{
Byte[] FileByteArray = new Byte[FileLength];
Stream StreamObject = UpFile.InputStream;
StreamObject.Read(FileByteArray,0,FileLength);
dr["c_image"]=FileByteArray; }
}
catch
{
Response.Write("<script defer>alert(\"图片格式不正确!\")</script>");
return;
}
}
读取:try
{
byte[] bys = (byte[])row["c_image"];
if(bys.Length > 100)
Response.OutputStream.Write(bys, 0, bys.Length);
Response.Write("没有图片!");
}
catch
{
Response.Write("没有图片!");
return;
}
{
//将原始图片缩放为指定大小的图片
System.Drawing.Bitmap b = new System.Drawing.Bitmap(Server.MapPath(strFileName));
if(b.Width > maxWidth)
{
if(nHeight < 1) nHeight = b.Height; Bitmap result = new Bitmap(nWidth,nHeight);
Graphics g = Graphics.FromImage((System.Drawing.Image)result);
g.DrawImage(b,0,0,nWidth,nHeight);
int index=strFileName.LastIndexOf("/");
string strForeside="";
if(index>0) strForeside=strFileName.Substring(0,index+1);
strFileName = strForeside+"Temp"+strFileName.Substring(strFileName.Length-4); result.Save(Server.MapPath(strFileName)); result.Dispose();
g.Dispose();
}
b.Dispose(); return strFileName;
}