Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getImage() or createImage() with picture stored in database

Status
Not open for further replies.

TheInsider

Programmer
Jul 17, 2000
796
CA
Hi,

I have a SQL Server database that stores pictures in a table. I have an applet that must retrieve certain images based on certain conditions. For security reason I do not want the applet to have direct access to the database (i.e. connection info), but rather have an ASP page control the selection of the image something like:
Code:
<%
Response.ContentType = "image/jpeg"
Response.BinaryWrite Recordset("MyPicture")
%>
This works fine when embedding the above into an HTML page like
Code:
<img src="PicLoader.asp">
; however, Java doesn't seem to allow the loading of an Image from an ASP page using getImage(). I even tried removing the
Code:
Response.ContentType = "image/jpeg"
portion of the ASP page, so that the returned stream was 100% pure jpg image data, but that didn't work either. I also tried retrieving the ASP output stream into a byte array and then using createImage(), but haven't had any success with that approach thus far (I just get garbage painted onto the canvas). Unfortunately, I don't have my code in front of me right now or I would paste what I have, but this really shouldn't be that difficult to do... I'm just fairly new to Java.

Thanks in advance,

The Insider
 
I can't what this has to do with Java. Unless you mean JavaScript, which is nothing to do with Java.

Tim
 
It's a Java Applet... for security reasons it gets its picture data for the Image objects from an ASP output stream, which in turn gets the pictures from a table in a SQL Server database.
 
Don't let the ASP part throw you off, it is not a conventional ASP page. It ONLY returns the file data for a jpeg image. The Applet is not on the same page as this ASP script. The Applet only calls the ASP page internally and saves its output stream to a variable.

The questions is: If I have a bunch of bytes somewhere that make up a jpeg image, how can I get them into an Image object? The most obvious way would be
Code:
Image pic = getImage(new URL("[URL unfurl="true"]http://localhost/PicLoader.asp"));[/URL]
but this doesn't work, presumably getImage requires a ".jpg" or ".gif" extension. So I tried capturing the stream from the ASP page into a byte array and then using createImage(), but I'm a little unsure as to how to do that.

Thank you for any help you can provide.
 
Whats the error then ? Does it give you a stack trace or exception ?

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Sorry TheInsider, I missed the 'applet' bit. My fault, must read slower [smile].

Lets see what error your 'getImage' line throws out, and we'll take it from there.

Tim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top