Solved

ASP.Net/VB:   thumbnail images from database

Posted on 2006-07-08
10
218 Views
Last Modified: 2006-11-18
I have a sculptor's website to complete, but I'm stuck on the Gallery portion of the site. Due to security and other concerns, the images are stored in a database as BLOB data. Please don't waste your answer on telling me to change it to directory-based storage, okay? I'm just following orders here. Anyway, I have a simple getImage page that will retrieve single images from the SQL db with no problem. (I found the code on the Net somewhere.) The page has no UI, just code I call from an 'OpenArt' page, using the following code to set the image URL for an <asp:image> tag:  imgArt.imageURL = "../getImg.aspx?id=1"

In the gallery there is a list of art pieces, each being an <asp:hyperlink>. When the user clicks a link, I grab the imgID from a session variable, enabling the user to see the piece's image, the price, et cetera.

Well, the artist now wants thumbnail images instead of hyperlinks. That blows my system out of the water.

NOTE: storing thumbnails in the database is not an option. The artist must be able to maintain the site herself, and she lacks the skills to make her own thumbnail images. Thumbnails must be made on the fly in this case.

I can't get the getImg.aspx page to respond to anything I pass in the queryString, and I don't understand the '?id=1' part of the URL (getImg.aspx?id=1) I use to call the page. Where does this 'id' come from? Right now I'm using a session variable to provide the imgID for the db retrieval sproc (note the indented line below). This obviously won't work for multiple images on a single Gallery page. I've tried no less than 20 links around the Net to try to figure this out, and I'm just tired of it. Thanks for any help I can get.

Here's the code for getImg.aspx:

'--------------------BEGIN CODE--------------

Sub Page_load()
 dim objConn as sqlConnection
 dim objCmdGetImg as sqlCommand
 dim strConn as string = ConfigurationSettings.AppSettings("dbConnStr")
 dim rdrGetImg as sqlDataReader
 objConn = new sqlConnection(strConn)
 objConn.open
 Try
  objCmdGetImg = new sqlCommand("db_getImg", objConn)
  objCmdGetImg.commandType = commandType.storedProcedure

                 objCmdGetImg.Parameters.Add("@imgID", sqlDBType.bigint).value = Session("imgID")

  rdrGetImg = objCmdGetImg.executeReader(CommandBehavior.CloseConnection)
  if rdrGetImg.hasRows then
   Do While rdrGetImg.Read
    Response.ContentType = rdrGetImg.Item(0)
    Response.BinaryWrite(rdrGetImg.Item(1))
   Loop
   rdrGetImg.close
   objCmdGetImg.dispose
  end if
 Catch SQLexc As SqlException
  Response.Write("Read Failed : " & SQLexc.ToString())
 End Try
End Sub

'--------------------END CODE--------------
0
Comment
Question by:k3n51mm
  • 3
  • 2
10 Comments
 
LVL 14

Accepted Solution

by:
Ramuncikas earned 250 total points
ID: 17067327
In case you use session variable:
objCmdGetImg.Parameters.AddWithValue("@imgID", Session("imgID"))

In case you use query string (like getImg.aspx?id=1):
objCmdGetImg.Parameters.AddWithValue("@imgID", Request.QueryString.Item("id"))
0
 
LVL 12

Assisted Solution

by:deanvanrooyen
deanvanrooyen earned 250 total points
ID: 17067369
this is how you create a thumbnail from an image - not sure how to read it from the db , havent done that yet - is is into some sort of stream? when you create the bitmap you can pass a stream to the constructor

using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;

                        Bitmap b = new Bitmap(stream);
                        Image im = b.GetThumbnailImage( 100, 100,  new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero);

        public bool ThumbnailCallback()
        {
            return true;
        }

then in in a grid
0
 
LVL 12

Expert Comment

by:deanvanrooyen
ID: 17306124
if he needs help with the stream read and seroalization let me know hopefully, he was helped a bit
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 12

Expert Comment

by:deanvanrooyen
ID: 17315020
thanks
0
 
LVL 14

Expert Comment

by:Ramuncikas
ID: 17323817
No objections
Thanks
0
 
LVL 1

Author Comment

by:k3n51mm
ID: 17335639
Sure, go ahead and split it, thx
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now