Solved

ASP.Net/VB:   thumbnail images from database

Posted on 2006-07-08
10
222 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

691 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