问题描述
DataTable dt3 = dbo.GetRecordsWithQuery(选择id,'''作为url,图像,''''作为拇指从图像顺序通过id desc);
for(int i = 0; i< dt3.Rows.Count; i ++)
{
byte [] val =(byte [])dt3 .Rows [i] [2];
MemoryStream ms = new MemoryStream(val);
System.Drawing.Image newImage = System .Drawing.Image.FromStream(ms);
newImage.Save(Server.MapPath(〜/ Images / temp / img+ i.ToString()+.jpg));
dt3.Rows [i] [1] =Images / temp / img+ i.ToString()+.jpg;
}
在这里,我将保存的图像检索为图像网址。但我不知道如何检索缩略图..任何人都可以帮助我吗?
提前谢谢:)
DataTable dt3 = dbo.GetRecordsWithQuery("select id,'''' as url,image,'''' as thumb from Image order by id desc");
for (int i = 0; i < dt3.Rows.Count; i++)
{
byte[] val = (byte[])dt3.Rows[i][2];
MemoryStream ms = new MemoryStream(val);
System.Drawing.Image newImage = System.Drawing.Image.FromStream(ms);
newImage.Save(Server.MapPath("~/Images/temp/img" + i.ToString() + ".jpg"));
dt3.Rows[i][1] = "Images/temp/img" + i.ToString() + ".jpg";
}
Here i retrieve saved image as image url. But i didnt know how to retrieve as thumbnail.. Can anyone help me ?
Thanks in advance :)
推荐答案
Image.GetThumbnailImage Method
来执行此任务。
请参阅MSDN:
]
这是你可以做的代码示例:
to perform this task.
see MSDN here:
http://msdn.microsoft.com/en-us/library/system.drawing.image.getthumbnailimage.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-2[^]
that''s a code example of what you could do:
public bool ThumbnailCallback()
{
return false;
}
//your code below...
DataTable dt3 = dbo.GetRecordsWithQuery("select id,'''' as url,image,'''' as thumb from Image order by id desc");
for (int i = 0; i < dt3.Rows.Count; i++)
{
byte[] val = (byte[])dt3.Rows[i][2];
MemoryStream ms = new MemoryStream(val);
System.Drawing.Image newImage = System.Drawing.Image.FromStream(ms);
newImage.Save(Server.MapPath("~/Images/temp/img" + i.ToString() + ".jpg"));
dt3.Rows[i][1] = "Images/temp/img" + i.ToString() + ".jpg";
// get thumbnail
Image.GetThumbnailImageAbort myCallback = new Image.GetThumbnailImageAbort(ThumbnailCallback);
Image myThumbnail = newImage.GetThumbnailImage(40, 40, myCallback, IntPtr.Zero);
e.Graphics.DrawImage(myThumbnail, 150, 75);
// save thumbnail
myThumbnail .Save(Server.MapPath("~/Images/temp/thumb" + i.ToString() + ".jpg"));
}
Valery。
Valery.
这篇关于如何从选择查询中检索保存的图像作为缩略图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!