473,386 Members | 1,786 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

GetThumbnailImage

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) ;
}
Nov 16 '05 #1
5 5607
TJS
http://www.dotnetjunkies.com/HowTo/C...8DBEC7F25.dcik
"Andrew Banks" <ba****@nojunkblueyonder.co.uk> wrote in message
news:o2*******************@news-text.cableinet.net...
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) ;
}

Nov 16 '05 #2
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" <ba****@nojunkblueyonder.co.uk> wrote in message
news:o2*******************@news-text.cableinet.net...
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) ;
}

Nov 16 '05 #3
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" <no****@here.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
http://www.dotnetjunkies.com/HowTo/C...8DBEC7F25.dcik

"Andrew Banks" <ba****@nojunkblueyonder.co.uk> wrote in message
news:o2*******************@news-text.cableinet.net...
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) ;
}


Nov 16 '05 #4
Hi Andrew,

"Andrew Banks" <ba****@nojunkblueyonder.co.uk> wrote in message
news:o2*******************@news-text.cableinet.net...
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
Nov 16 '05 #5
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.


Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Comcast | last post by:
I understand that one of the limitations of the Image.GetThumbnailImage() function is that it's not really good for creating "large" thumbnails because if it exists in the image file, the function...
5
by: John | last post by:
I am trying to convert the regular sized images in a directory to thumbnails and then display the thumbnails in a datalist. My code below is displaying the first image and nothing else after it. ...
5
by: Andrew Banks | last post by:
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...
1
by: GrandpaB | last post by:
I am having difficulty implementing the GetThumbnailImage method. I have read the "Help" files on this method, but remain confused. My problem is understanding the last two parameters that the...
0
by: billsahiker | last post by:
Does anyone know how to call GetthumbnailImage in VB6? I am posting this here because .NET is where most of the use of GDIPlus is found and many of you are/were VB6 folks. I registered the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.