Click here to Skip to main content
15,893,266 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 :)
Posted
Updated 18-Jan-13 20:07pm
v2

As far as I'm aware, you can't convert it to a thumbnail via SQL query, you have to convert it your application code either when you save it (e.g. save it with a thumbnail version in addition to the full size) or after you retrieve it from the database. For these sorts of tasks I find ImageMagick[^] to be useful. And specifically, here's a page on generating thumbails[^].
 
Share this answer
 
Hello.

you can use
Image.GetThumbnailImage Method
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900