我想知道使用文件为现有图像制作缩略图而不是将其保存到磁盘中是否有任何缺点。有没有与此相关的内存问题?!
我的代码:
// thumbnails.aspx
protected void Page_Load(object sender, EventArgs e)
{
string file = Request.QueryString["i"];
if (file == null)
return;
if (!IsFileExists(file))
return;
Thumb(file);
}
public void Thumb(string file)
{
System.Drawing.Image image = System.Drawing.Image.FromFile(Server.MapPath(file));
System.Drawing.Image thumbnailImage = image.GetThumbnailImage(70, 70, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero);
System.IO.MemoryStream imageStream = new System.IO.MemoryStream();
thumbnailImage.Save(imageStream, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] imageContent = new Byte[imageStream.Length];
imageStream.Position = 0;
imageStream.Read(imageContent, 0, (int)imageStream.Length);
Response.ContentType = "image/jpeg";
Response.BinaryWrite(imageContent);
}
答案 0 :(得分:0)
然后将其存储在文件中。每次使用GDI转换为缩略图将使用大量的cpu周期。您也可以将图像存储在数据库中而不是存储在磁盘上。