关于数据库中保存图片 http://www.programfan.com/showarticle.asp?id=2105 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://home.jlu.edu.cn/~hoofi/dbbase/603565.xml 下面是我的程序片断 //保存图片 if(this.bImageChanged) { try { MemoryStream ms = new MemoryStream (); this.picImage.Image.Save (ms, System.Drawing.Imaging.ImageFormat.Bmp); byte [] myData = new Byte [ms.Length ]; ms.Position = 0; ms.Read (myData,0,Convert.ToInt32 (ms.Length )); myDataRow["缩略图"] = myData; } catch(System.Exception ee) { MessageBox.Show(ee.Message); } } this.bImageChanged=false; return true; } //显示缩略图 if(this.myDataRow["缩略图"]!=DBNull.Value) { try { Byte[] byteBLOBData = new Byte[0]; byteBLOBData = (Byte[])myDataRow["缩略图"]; MemoryStream stmBLOBData = new MemoryStream(byteBLOBData); this.picImage.Image= Image.FromStream(stmBLOBData); } catch(Exception ex) { MessageBox.Show(ex.Message); } } this.picImage.Refresh(); DataAdapter.MissingSchemaAction = MissingSchemaAction.AddWithKey; FileInfo aFile = new FileInfo(@""+directory); if (!aFile.Exists) { MessageBox.Show("请检查相片文件:"+Field+"路径名:"+directory+"是否正确?", "输入错误,文件不存在!", MessageBoxButtons.OK, MessageBoxIcon.Question); return; } //===========处理文件的格式,如果不是正确格式,报错。 Image i = Image.FromFile(directory); FileStream fs; /*if (i.Size.Height != 168 || i.Size.Width != 104) { //===========处理图片缩小功能 System.Drawing.Image image = new Bitmap(aFile.FullName);//得到原图 System.Drawing.Image pThumbnail = image.GetThumbnailImage(168, 104, null, new IntPtr()); //创建缩小的图的大小 Graphics g=Graphics.FromImage(pThumbnail); g.DrawImage(pThumbnail,10,10, pThumbnail.Width, pThumbnail.Height); //将原图画到缩小的图上 pThumbnail.Save(@"C:\WINNT\Temp\a.Jpeg",ImageFormat.Jpeg); //保存 g.Dispose(); fs = new FileStream (@"C:\WINNT\Temp\a.Jpeg" , FileMode.OpenOrCreate, FileAccess.Read); } else { fs = new FileStream (@"" + directory , FileMode.OpenOrCreate, FileAccess.Read); }*/ fs = new FileStream (@"" + directory , FileMode.OpenOrCreate, FileAccess.Read); //==================读文件并存储到数据库中 byte[] MyData= new byte[fs.Length]; fs.Read(MyData, 0, System.Convert.ToInt32(fs.Length)); tempDatarow[""+Field] = MyData; System.IO.MemoryStream stream = new System.IO.MemoryStream(MyData, true); stream.Write(MyData, 0, MyData.Length); Bitmap bmp = new Bitmap(stream); if( bmp.Width != 168 && bmp.Height != 104) { Bitmap bmp1 = new Bitmap(bmp, new Size(168,104)); picture.Image = bmp1; } else picture.Image = bmp; stream.Close(); fs.Close(); //=================删除临时文件。 /*if (System.IO.File.Exists(@"C:\WINNT\Temp\a.Jpeg")) { System.IO.File.Delete(@"C:\WINNT\Temp\a.Jpeg"); }*/ http://expert.csdn.net/Expert/topicview.asp?id=1690497 http://www.codeproject.com/cs/database/albumviewer.asp电子像册,sqlServer iframe页接收parent页的值??? System.ArgumentNullException: 值不能为空 怎样实现查询的功能 刚刚学C#者 c# winform 如何做凹凸效果的按钮 如何去除string中的标点 接昨天结帖的那个问题 在一个线程里show一个窗体,但窗体里的控件不显示,是什么原因啊? 怎样使datagrid的某个数据列成为可编辑列? 目录问题,简单! ?如何判断一个字符串是不是数字格式? 【求助】关于C#开发 C#中有没有数据库连接池啊,欢迎up,散分了!
//保存图片
if(this.bImageChanged)
{
try
{
MemoryStream ms = new MemoryStream ();
this.picImage.Image.Save (ms, System.Drawing.Imaging.ImageFormat.Bmp);
byte [] myData = new Byte [ms.Length ];
ms.Position = 0;
ms.Read (myData,0,Convert.ToInt32 (ms.Length ));
myDataRow["缩略图"] = myData; }
catch(System.Exception ee)
{
MessageBox.Show(ee.Message);
}
}
this.bImageChanged=false;
return true;
}
//显示缩略图
if(this.myDataRow["缩略图"]!=DBNull.Value)
{
try
{
Byte[] byteBLOBData = new Byte[0];
byteBLOBData = (Byte[])myDataRow["缩略图"];
MemoryStream stmBLOBData = new MemoryStream(byteBLOBData);
this.picImage.Image= Image.FromStream(stmBLOBData);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
this.picImage.Refresh();
FileInfo aFile = new FileInfo(@""+directory);
if (!aFile.Exists)
{
MessageBox.Show("请检查相片文件:"+Field+"路径名:"+directory+"是否正确?", "输入错误,文件不存在!", MessageBoxButtons.OK, MessageBoxIcon.Question);
return;
}
//===========处理文件的格式,如果不是正确格式,报错。
Image i = Image.FromFile(directory); FileStream fs;
/*if (i.Size.Height != 168 || i.Size.Width != 104)
{
//===========处理图片缩小功能
System.Drawing.Image image = new Bitmap(aFile.FullName);//得到原图
System.Drawing.Image pThumbnail = image.GetThumbnailImage(168, 104, null, new IntPtr()); //创建缩小的图的大小
Graphics g=Graphics.FromImage(pThumbnail);
g.DrawImage(pThumbnail,10,10, pThumbnail.Width, pThumbnail.Height); //将原图画到缩小的图上
pThumbnail.Save(@"C:\WINNT\Temp\a.Jpeg",ImageFormat.Jpeg); //保存
g.Dispose();
fs = new FileStream (@"C:\WINNT\Temp\a.Jpeg" , FileMode.OpenOrCreate, FileAccess.Read);
}
else
{
fs = new FileStream (@"" + directory , FileMode.OpenOrCreate, FileAccess.Read);
}*/
fs = new FileStream (@"" + directory , FileMode.OpenOrCreate, FileAccess.Read);
//==================读文件并存储到数据库中
byte[] MyData= new byte[fs.Length];
fs.Read(MyData, 0, System.Convert.ToInt32(fs.Length));
tempDatarow[""+Field] = MyData; System.IO.MemoryStream stream = new System.IO.MemoryStream(MyData, true);
stream.Write(MyData, 0, MyData.Length); Bitmap bmp = new Bitmap(stream); if( bmp.Width != 168 && bmp.Height != 104)
{
Bitmap bmp1 = new Bitmap(bmp, new Size(168,104));
picture.Image = bmp1;
}
else
picture.Image = bmp;
stream.Close(); fs.Close();
//=================删除临时文件。
/*if (System.IO.File.Exists(@"C:\WINNT\Temp\a.Jpeg"))
{
System.IO.File.Delete(@"C:\WINNT\Temp\a.Jpeg");
}*/
电子像册,sqlServer