不能够显示在中继器控制的图像为[缩略图图像]

问题描述:

我已经在数据表imgae路径[ID,路径]现在本想不能够显示在中继器控制的图像为[缩略图图像]

ex: id path 
    1 F:\R&D\RD\RD\Images\a1.JPG; 
    2 F:\R&D\RD\RD\Images\a2.JPG; 
    3 F:\R&D\RD\RD\Images\a3.JPG; 

的值现在这些图像的尺寸宽×高(1018×768)。现在我需要将这些图像转换成略图

caling功能

**C_Thumbnails(100, "F:\R&D\RD\RD\Images\a1.JPG", "F:\R&D\RD\RD\Images]thum.jpg")** 
public static void C_Thumbnails(int size, string FilePath, string ThumbPath) 
     { 

      System.Drawing.Image image = System.Drawing.Image.FromFile(FilePath); 

      try 
      { 
       int thumbHeight, thumbWidth; 

       decimal h = image.Height; 

       decimal w = image.Width; 

       if (image.Height > image.Width) 
       { 

        thumbHeight = size; 

        decimal tWidth = (w/h) * thumbHeight; 

        thumbWidth = Convert.ToInt32(tWidth); 

       } 

       else 
       { 

        thumbWidth = size; 

        decimal tHeight = (h/w) * thumbWidth; 

        thumbHeight = Convert.ToInt32(tHeight); 

       } 
       System.Drawing.Image thumbnailImage = image.GetThumbnailImage(thumbWidth, thumbHeight, null, IntPtr.Zero); 
       image.Dispose(); 
       thumbnailImage.Save(ThumbPath, System.Drawing.Imaging.ImageFormat.Jpeg); 

      } 

      catch (Exception ex) 
      { 
       image.Dispose(); 
       throw ex; 
      } 

     } 

像这个我coverting成缩略图。但在这里我保存缩略图图像路径F:\ R & D \ RD \ RD \ Images \ thum.jpg

有没有什么办法,而不保存在磁盘的缩略图,以及如何绑定中继控制器中的新缩略图图像,我需要在那里显示图像。但是如果用户一旦点击thumnail图像就会弹出一个原始图像。

如果任何人已经做了这个功能任何地方让我知道 从过去两天工作在这个解决方案。 任何帮助,将不胜感激

现在我已经加入这行代码 改变代码 像在中继器控制该

public void ProcessRequest(HttpContext context) 
    { 
     string imageid = context.Request.Params["ImageID"]; 
     string thumbnail = context.Request.Params["thumbnail"]; 
     SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString); 
     connection.Open(); 
     SqlCommand command = new SqlCommand("select Image from Image where ImageID=" + imageid, connection); 
     SqlDataReader dr = command.ExecuteReader(); 
     dr.Read(); 

     string filePath = dr["image"].ToString(); 
     dr.Close(); 

     if (!System.IO.File.Exists(filePath)) 
     { 
      //you have a problem 
      return; 
     } 
     if (context.Request.Params["thumbnail"] == "true") 
     { 
      //TODO: the thumbnail 
      // Image thumbnailImage = originalImage.GetThumbnailImage to generate thumbnail then 
      Response.ClearContent(); 
      Response.ClearHeaders(); 
      Response.ContentType = "image/" + format; 
      thumbnailImage.Save(Response.OutputStream, imageFormat); 
      thumbnailImage.Dispose(); 

     } 
     else 
     { //stream directly the image fromdisk 
      System.IO.FileStream fs = System.IO.File.OpenRead(filepath); 
      const int ChunkSize = 10000; 
      Byte[] buffer = new Byte[ChunkSize]; 
      long dataLengthToRead = fs.Length; 

      while (dataLengthToRead > 0) 
      { 
       int lengthRead = fs.Read(buffer, 0, ChunkSize); 
       Response.OutputStream.Write(buffer, 0, lengthRead); 
       System.Web.HttpContext.Current.Response.Flush(); 
       dataLengthToRead = dataLengthToRead - lengthRead; 
      } 
      fs.Close(); 
     } 
    } 


} 

后“‘_空白’,”工具栏=无, ) 我的缩略图图像没有显示,但是一旦我点击我的缩略图图像,我就可以看到新的弹出图像中的整个图像

您应该使用Photo Image Handler将磁盘中的页面提供给客户端。 然后在Repeater控件

<a href="ImageHandler.ashx?thumbnail=false&id='<%# Eval("ID")%>'> 
     <img src="ImageHandler.ashx?thumbnail=true&id='<%# Eval("ID")%>' border='0'/> 
    </a> 

的IDEEA是不是在文件的实际路径/名通过,但该项目的ID你想查看。然后,该处理程序将:

public void ProcessRequest(System.Web.HttpContext context) 
    { 
     string filePath = //TODO: Get File Path from ItemID = context.Request.Params["id"] 
     if (!System.IO.File.Exists(filePath)) 
     { 
      //you have a problem 
      return; 
     } 
     if(context.Request.Params["thumbnail"]=="true") 
     { 
      //TODO: the thumbnail 
      // Image thumbnailImage = originalImage.GetThumbnailImage to generate thumbnail then 
      Response.ClearContent(); 
      Response.ClearHeaders(); 
      Response.ContentType = "image/" + format; 
      thumbnailImage.Save(Response.OutputStream, imageFormat); 
      thumbnailImage.Dispose(); 

     } else 
     { //stream directly the image fromdisk 
      System.IO.FileStream fs = System.IO.File.OpenRead(filepath); 
      const int ChunkSize = 10000; 
      Byte[] buffer = new Byte[ChunkSize]; 
      long dataLengthToRead = fs.Length; 

      while (dataLengthToRead > 0) 
      { 
       int lengthRead = fs.Read(buffer, 0, ChunkSize); 
       Response.OutputStream.Write(buffer, 0, lengthRead); 
       System.Web.HttpContext.Current.Response.Flush(); 
       dataLengthToRead = dataLengthToRead - lengthRead; 
      } 
      fs.Close(); 
} 
} 
+0

thnaks对我试过我们的代码是不显示thumbnal图像仍然但是当我点击图片布通,但图像在新弹出的ip – happysmile 2009-11-14 10:01:41

+0

有一个“TODO所示的回放:缩略图“。只需粘贴之前使用的代码来生成缩略图,但这次将tumbnailImage保存到Response的OutputStream而不是磁盘。它应该工作 – Radu094 2009-11-14 11:18:09