File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes How can I resize an image from database table and show it Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "How can I resize an image from database table and show it" Watch "How can I resize an image from database table and show it" New topic
Author

How can I resize an image from database table and show it

Shounak Kundu
Ranch Hand

Joined: Jul 29, 2010
Posts: 60

Hi, I am trying to select an image from the table and change it to a thumbnail. On clicking the thumbnail, the original sized image will appear.

How can I do that ? Here's my code.


You can see, I have tried to use BufferedImage, but could not. Can you help me ?


Shounak
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18127
    
    8

Well, first of all you'll want to get that code out of a JSP and into a servlet where it belongs. By putting it in a JSP you are mixing the output of your Java code with the output of the JSP -- all that HTML code. That's guaranteed to produce garbage instead of an image.
Shounak Kundu
Ranch Hand

Joined: Jul 29, 2010
Posts: 60

Actually , I am getting the images properly.
Now, I am trying to convert it first to a thumbnail, and then on clicking the thumbnail it'll show the original image.

How can I do that ?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60053
    
  65

You use <img> tags to show images. The src of the tags reference servlets that serve the image data.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Shounak Kundu
Ranch Hand

Joined: Jul 29, 2010
Posts: 60

Bang on target dude. This part of code produces the image :


How can I put this within an <img src=""> ? Because , I have tried this , just to end up showing an error ....


But it is showing error , when I am giving the scriplet tag ...

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60053
    
  65

In HTML do put the image data into the HTML page? Of course not. Why are you trying to do that with a JSP, which just creates an HTML page to send to the client?

The image data is useless in the JSP. The JSP will use the <img> tag, as I have already said, whose src attribute is the URL of a servlet that supplies the image response.
Shounak Kundu
Ranch Hand

Joined: Jul 29, 2010
Posts: 60

Ok. So, are you trying to say to do something like this :

Create a jsp page. In that page, create an <img> tag, something like this:




And in the servlet :



Are you sure , this is gonna work ? Because , the image will not be scaled down , right ?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60053
    
  65

If the image needs processing, it can be done in the servlet.
Shounak Kundu
Ranch Hand

Joined: Jul 29, 2010
Posts: 60


Bear Bibeault said,

If the image needs processing, it can be done in the servlet.





How can I process an image that I get from database ?


I am new to all these , please guide me.

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60053
    
  65

There is nothing in the JSP or servlet realm for this. Look into JAI or other Java APIs for image manipulation.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How can I resize an image from database table and show it
 
Similar Threads
retrieve images from a database
I cannot obtain the enitre path of image
how to insert an image into MYSQL database using java
Only for one data in the text box
how to upload pdf files to My sql with java