473,395 Members | 1,440 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,395 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 18 '05 #1
5 1467
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 18 '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 18 '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 18 '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 18 '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 18 '05 #6

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

Similar topics

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: 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. ...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.