Solved

ASP.Net/VB:   thumbnail images from database

Posted on 2006-07-08
10
220 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
designing in object programming 12 80
jQuery - following an example but can I save data server side? 20 51
Expression Evaluater 3 28
C# LINQ ForEach() question 6 29
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

825 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