Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > GetThumbnailImage

Reply
Thread Tools

GetThumbnailImage

 
 
Andrew Banks
Guest
Posts: n/a
 
      04-16-2004
Is it possible to use GetThumbnailImage with images being pulled from an SQL
DB and if so how? All examples I've seen refer to working with an actual
image stored on the server.

My code for pulling the image from the DB is below if it makes a difference.

Thanks in advance

private void Page_Load(object sender, System.EventArgs e)
{
string imageID = Request.QueryString["ID"];
SqlDataReader imageContent = GetImages(imageID);
imageContent.Read();
Response.ContentType = imageContent["ContentType"].ToString();

Response.OutputStream.Write((byte[])imageContent["CoverShot"],0,System.Conve
rt.ToInt32(imageContent["ContentLength"]));
Response.End();
}
private SqlDataReader GetImages(string imageID)
{
SqlConnection con = new
SqlConnection(System.Configuration.ConfigurationSe ttings.AppSettings.Get("Co
nRead"));
SqlCommand cmd = new SqlCommand("SELECT CoverShot, ContentType,
ContentLength FROM Products WHERE ProductID = '" + imageID + "'",con);
con.Open();
return cmd.ExecuteReader(CommandBehavior.CloseConnection) ;
}


 
Reply With Quote
 
 
 
 
TJS
Guest
Posts: n/a
 
      04-16-2004
http://www.dotnetjunkies.com/HowTo/C...8DBEC7F25.dcik


"Andrew Banks" <(E-Mail Removed)> wrote in message
news2Mfc.382$(E-Mail Removed)...
> Is it possible to use GetThumbnailImage with images being pulled from an

SQL
> DB and if so how? All examples I've seen refer to working with an actual
> image stored on the server.
>
> My code for pulling the image from the DB is below if it makes a

difference.
>
> Thanks in advance
>
> private void Page_Load(object sender, System.EventArgs e)
> {
> string imageID = Request.QueryString["ID"];
> SqlDataReader imageContent = GetImages(imageID);
> imageContent.Read();
> Response.ContentType = imageContent["ContentType"].ToString();
>
>

Response.OutputStream.Write((byte[])imageContent["CoverShot"],0,System.Conve
> rt.ToInt32(imageContent["ContentLength"]));
> Response.End();
> }
> private SqlDataReader GetImages(string imageID)
> {
> SqlConnection con = new
>

SqlConnection(System.Configuration.ConfigurationSe ttings.AppSettings.Get("Co
> nRead"));
> SqlCommand cmd = new SqlCommand("SELECT CoverShot, ContentType,
> ContentLength FROM Products WHERE ProductID = '" + imageID + "'",con);
> con.Open();
> return cmd.ExecuteReader(CommandBehavior.CloseConnection) ;
> }
>
>



 
Reply With Quote
 
 
 
 
Luke Venediger
Guest
Posts: n/a
 
      04-16-2004
Hi there,

Your image will be stored in the database as type Image. You can do the
following to pull it out, assuming you want to get the thumbnail for a
particular image:

string sql = "SELECT thumbnail FROM tb_Products WHERE ProductID = " +
ProductID;
SqlCommand command = new SqlCommand();
command.CommandType = CommandType.Text;
command.CommandText = sql;
command.Connection = yourConnectionObject;

// Get the raw image data
SqlDataAdapter adapter = new SqlDataAdapter(command);
DataTable resultDt = new DataTable();
adapter.Fill(resultDt);
command.Close();
byte[] imageData = (byte[])resultDt.Rows[0]["thumbnail"];

// Send it to the caller
MemoryStream memStream = new MemoryStream(imageData);
memStream.WriteTo(Response.OutputStream);

Cheers,

Luke Venediger
http://blogdotnet.blogspot.com


"Andrew Banks" <(E-Mail Removed)> wrote in message
news2Mfc.382$(E-Mail Removed)...
> Is it possible to use GetThumbnailImage with images being pulled from an

SQL
> DB and if so how? All examples I've seen refer to working with an actual
> image stored on the server.
>
> My code for pulling the image from the DB is below if it makes a

difference.
>
> Thanks in advance
>
> private void Page_Load(object sender, System.EventArgs e)
> {
> string imageID = Request.QueryString["ID"];
> SqlDataReader imageContent = GetImages(imageID);
> imageContent.Read();
> Response.ContentType = imageContent["ContentType"].ToString();
>
>

Response.OutputStream.Write((byte[])imageContent["CoverShot"],0,System.Conve
> rt.ToInt32(imageContent["ContentLength"]));
> Response.End();
> }
> private SqlDataReader GetImages(string imageID)
> {
> SqlConnection con = new
>

SqlConnection(System.Configuration.ConfigurationSe ttings.AppSettings.Get("Co
> nRead"));
> SqlCommand cmd = new SqlCommand("SELECT CoverShot, ContentType,
> ContentLength FROM Products WHERE ProductID = '" + imageID + "'",con);
> con.Open();
> return cmd.ExecuteReader(CommandBehavior.CloseConnection) ;
> }
>
>



 
Reply With Quote
 
Andrew Banks
Guest
Posts: n/a
 
      04-16-2004
Thanks TJS.

Only problem is I already have the image in the DB and want to dynamically
resize it onthe way out and not on the way in.

Any ideas how I would do this please?

"TJS" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
>

http://www.dotnetjunkies.com/HowTo/C...8DBEC7F25.dcik
>
>
> "Andrew Banks" <(E-Mail Removed)> wrote in message
> news2Mfc.382$(E-Mail Removed)...
> > Is it possible to use GetThumbnailImage with images being pulled from an

> SQL
> > DB and if so how? All examples I've seen refer to working with an actual
> > image stored on the server.
> >
> > My code for pulling the image from the DB is below if it makes a

> difference.
> >
> > Thanks in advance
> >
> > private void Page_Load(object sender, System.EventArgs e)
> > {
> > string imageID = Request.QueryString["ID"];
> > SqlDataReader imageContent = GetImages(imageID);
> > imageContent.Read();
> > Response.ContentType = imageContent["ContentType"].ToString();
> >
> >

>

Response.OutputStream.Write((byte[])imageContent["CoverShot"],0,System.Conve
> > rt.ToInt32(imageContent["ContentLength"]));
> > Response.End();
> > }
> > private SqlDataReader GetImages(string imageID)
> > {
> > SqlConnection con = new
> >

>

SqlConnection(System.Configuration.ConfigurationSe ttings.AppSettings.Get("Co
> > nRead"));
> > SqlCommand cmd = new SqlCommand("SELECT CoverShot, ContentType,
> > ContentLength FROM Products WHERE ProductID = '" + imageID + "'",con);
> > con.Open();
> > return cmd.ExecuteReader(CommandBehavior.CloseConnection) ;
> > }
> >
> >

>
>



 
Reply With Quote
 
Daniel Pratt
Guest
Posts: n/a
 
      04-16-2004
Hi Andrew,

"Andrew Banks" <(E-Mail Removed)> wrote in message
news2Mfc.382$(E-Mail Removed)...
> Is it possible to use GetThumbnailImage with images being pulled from an

SQL
> DB and if so how? All examples I've seen refer to working with an actual
> image stored on the server.
>
> My code for pulling the image from the DB is below if it makes a

difference.
>
> Thanks in advance


This is just "air" code, but it should give you the idea:

...
private void Page_Load(object sender, System.EventArgs e)
{
string imageID = Request.QueryString["ID"];
SqlDataReader imageContent = GetImages(imageID);
imageContent.Read();
Response.ContentType = imageContent["ContentType"].ToString();

MemoryStream imageData = new
MemoryStream((byte[])imageContent["CoverShot"]);

using(Image fullImage = new Bitmap(imageData))
{
using(Image thumbnailImage =
fullImage.GetThumbnailImage(...))
{
thumbnailImage.Save(Response.OutputStream, ...);
}
}

Response.End();
}
...

Regards,
Daniel


 
Reply With Quote
 
Peter Morris [Droopy eyes software]
Guest
Posts: n/a
 
      04-17-2004
Here is an example of how to accept a file uploaded from a webform, and
shrink it down in memory to a small sized image, maybe it will help?

http://www.howtodothings.com/showart...sp?article=682


--
Pete
-------
http://www.HowToDoThings.com
Read or write articles on just about anything

> Is it possible to use GetThumbnailImage with images being pulled from an

SQL
> DB and if so how? All examples I've seen refer to working with an actual
> image stored on the server.




 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
GetThumbnailImage Question rhungund@gmail.com ASP .Net 2 12-20-2005 09:46 PM
GetThumbnailImage help =?Utf-8?B?Q2hyaXM=?= ASP .Net 2 12-30-2004 04:05 AM
Generating Thumbnails (GetThumbnailImage) ... Fabricio Sperandio ASP .Net 8 10-19-2004 03:05 PM
GetThumbnailImage Question John ASP .Net 3 04-01-2004 07:06 PM
Workaround for GetThumbnailImage Problem? Comcast ASP .Net 1 07-16-2003 06:02 PM



Advertisments