Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 无法在[缩略图]的中继器控件中显示图像_Asp.net - Fatal编程技术网

Asp.net 无法在[缩略图]的中继器控件中显示图像

Asp.net 无法在[缩略图]的中继器控件中显示图像,asp.net,Asp.net,我在datatable[id,path]中有imgae path,现在这个值如下 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)。现在,我需要将这些图像转换为thumnail 校准函数 **C_Thumbnails(100,

我在datatable[id,path]中有imgae path,现在这个值如下

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)。现在,我需要将这些图像转换为thumnail

校准函数

**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;
            }

        }
像这样,我正在转换成缩略图像。但是在这里,我将缩略图保存在路径F:\R&D\RD\Images\thum.jpg

因此,有没有办法不将缩略图保存在磁盘中以及如何在repeater控件中绑定新的缩略图图像,我需要在那里显示图像。但是,如果用户单击thumnail图像,就会弹出原始图像

如果有人在任何地方做过这个功能,请告诉我 在过去2天内一直在处理此解决方案。 任何帮助都将不胜感激

现在更改代码后 像这样

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();
        }
    }


}
在中继器控制中,我添加了这行代码 “,”空白“,”工具栏=否,菜单栏=否“>”/> 我的缩略图不会静止显示,但单击我的缩略图后,我可以在新的弹出窗口中看到整个图像

您应该使用从磁盘到客户端的页面。 然后在中继器控制中

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

对于重播,我尝试了你的代码,它仍然没有显示缩略图图像,但当我单击图像按钮时,图像显示在新的弹出窗口中,这里有一个“待办事项:缩略图”“在代码中。。只需粘贴之前用于生成缩略图的代码,但这次将tumbnailImage保存到响应的OutputStream,而不是磁盘。那就行了
    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();
}
}