做程序一直涉及到图片的上传保存,以前保存图片无非是2种模式
1.直接用IO流写进数据库
2.数据库中保存路径,图片放到文件夹中
但是这两种都有弊端,IO流会导致数据库很大,也能还会引起数据库崩溃,而且读取速度慢;但是把图片放在文件夹中,图片多很了,管理图片又不方便,听见一朋友说可以用以下办法(具体我不是很清楚):
写个什么 Adapter 方便的在数据库和File之间转换(什么意思)?
写个Handler 数据库里面存储路径 需要的时候用IO读 ?
有没有那位知道这个是什么方法,谢谢指教。
1.直接用IO流写进数据库
2.数据库中保存路径,图片放到文件夹中
但是这两种都有弊端,IO流会导致数据库很大,也能还会引起数据库崩溃,而且读取速度慢;但是把图片放在文件夹中,图片多很了,管理图片又不方便,听见一朋友说可以用以下办法(具体我不是很清楚):
写个什么 Adapter 方便的在数据库和File之间转换(什么意思)?
写个Handler 数据库里面存储路径 需要的时候用IO读 ?
有没有那位知道这个是什么方法,谢谢指教。
====
可以建相应目录Dictionary
OneFileClass onefileclass = filesdataclass.anyFileClass.FindOneFile(this.GetFileName);
byte[] filebytes = onefileclass.filebytes;
string contenttype = this.GetContentType(onefileclass.filetype);
int imgWidth, imgHight; //Response.Write(this.GetSessionName + " " + this.GetIndex.ToString()); //测试
//Response.Write(filebytes.Length.ToString() + " " + contenttype); //测试
//Response.Write(onefileclass.cinvcode + " " + onefileclass.curlpath + " " + onefileclass.filelongth.ToString() + " " + onefileclass.filename + " " + onefileclass.filetype + " " + onefileclass.imageheight.ToString() + " " + onefileclass.imagewidth.ToString() + " " + onefileclass.upfile + "<br/>"); //测试 //begin 图片大小
if (!String.IsNullOrEmpty(this.GetImageWidth))
{
imgWidth = Convert.ToInt32(this.GetImageWidth);
if (onefileclass.imagewidth > imgWidth)
{
imgHight = imgWidth * onefileclass.imageheight / onefileclass.imagewidth;
}
else
{
imgWidth = onefileclass.imagewidth;
imgHight = onefileclass.imageheight;
}
System.Drawing.Image.GetThumbnailImageAbort callback = new System.Drawing.Image.GetThumbnailImageAbort(this.GetCallBack);
System.IO.MemoryStream ms = new System.IO.MemoryStream(filebytes);
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(ms);
System.Drawing.Image image = bitmap.GetThumbnailImage(imgWidth, imgHight, callback, System.IntPtr.Zero);
System.IO.MemoryStream ms2 = new System.IO.MemoryStream();
image.Save(ms2, onefileclass.imageformat);
filebytes = ms2.GetBuffer();
}
//end 图片大小 System.Web.HttpContext.Current.Response.Clear();
System.Web.HttpContext.Current.Response.ContentType = contenttype;
System.Web.HttpContext.Current.Response.OutputStream.Write(filebytes, 0, filebytes.Length); //for (int i = 0; i < filebytes.Length; i++)//测试
// System.Web.HttpContext.Current.Response.Write(filebytes[0].ToString() + " ");//测试
System.Web.HttpContext.Current.Response.End();