Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
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 Smile | :)
Posted 18-Jan-13 18:26pm
Edited 18-Jan-13 20:07pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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[^].
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 397
1 OriginalGriff 350
2 thatraja 205
3 Emre Ataseven 165
4 Shai Vashdi 150
0 Sergey Alexandrovich Kryukov 8,894
1 OriginalGriff 5,200
2 Peter Leow 3,955
3 Maciej Los 3,535
4 Abhinav S 3,208


Advertise | Privacy | Mobile
Web01 | 2.8.140415.2 | Last Updated 19 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid