GetThumbnailImage

Discussion in 'ASP .Net' started by Andrew Banks, Apr 16, 2004.

  1. Andrew Banks

    Andrew Banks Guest

    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.ConfigurationSettings.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);
    }
     
    Andrew Banks, Apr 16, 2004
    #1
    1. Advertising

  2. Andrew Banks

    TJS Guest

    http://www.dotnetjunkies.com/HowTo/C4A2ACC3-C6B4-4E4C-802A-85B8DBEC7F25.dcik


    "Andrew Banks" <> wrote in message
    news:eek:2Mfc.382$...
    > 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.ConfigurationSettings.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);
    > }
    >
    >
     
    TJS, Apr 16, 2004
    #2
    1. Advertising

  3. 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" <> wrote in message
    news:eek:2Mfc.382$...
    > 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.ConfigurationSettings.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);
    > }
    >
    >
     
    Luke Venediger, Apr 16, 2004
    #3
  4. Andrew Banks

    Andrew Banks Guest

    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" <> wrote in message
    news:%...
    >

    http://www.dotnetjunkies.com/HowTo/C4A2ACC3-C6B4-4E4C-802A-85B8DBEC7F25.dcik
    >
    >
    > "Andrew Banks" <> wrote in message
    > news:eek:2Mfc.382$...
    > > 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.ConfigurationSettings.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);
    > > }
    > >
    > >

    >
    >
     
    Andrew Banks, Apr 16, 2004
    #4
  5. Andrew Banks

    Daniel Pratt Guest

    Hi Andrew,

    "Andrew Banks" <> wrote in message
    news:eek:2Mfc.382$...
    > 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
     
    Daniel Pratt, Apr 16, 2004
    #5
  6. 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/showarticle.asp?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.
     
    Peter Morris [Droopy eyes software], Apr 17, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Comcast
    Replies:
    1
    Views:
    563
    Comcast
    Jul 16, 2003
  2. John

    GetThumbnailImage Question

    John, Apr 1, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    2,102
    =?Utf-8?B?QmlsbCBCb3Jn?=
    Apr 1, 2004
  3. Fabricio Sperandio

    Generating Thumbnails (GetThumbnailImage) ...

    Fabricio Sperandio, Oct 18, 2004, in forum: ASP .Net
    Replies:
    8
    Views:
    4,420
    ESPN Lover
    Oct 19, 2004
  4. =?Utf-8?B?Q2hyaXM=?=

    GetThumbnailImage help

    =?Utf-8?B?Q2hyaXM=?=, Dec 29, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    3,694
    =?Utf-8?B?Q2hyaXM=?=
    Dec 30, 2004
  5. Replies:
    2
    Views:
    9,551
Loading...

Share This Page