0
我已經在數據表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();
}
}
}
後「‘_空白’,」工具欄=無, ) 我的縮略圖圖像沒有顯示,但是一旦我點擊我的縮略圖圖像,我就可以看到新的彈出圖像中的整個圖像
thnaks對我試過我們的代碼是不顯示thumbnal圖像仍然但是當我點擊圖片布通,但圖像在新彈出的ip – happysmile 2009-11-14 10:01:41
有一個「TODO所示的回放:縮略圖「。只需粘貼之前使用的代碼來生成縮略圖,但這次將tumbnailImage保存到Response的OutputStream而不是磁盤。它應該工作 – Radu094 2009-11-14 11:18:09