473,322 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

How to get the side of an image from the database?

I am trying to retreive a image from mysql database and display it on a jsp page.

But I am not getting how to set the size of the image...
Jan 1 '11 #1
1 1540
nathj
938 Expert 512MB
Hi,

You need to used the BufferedImage class and the ImageIO class. I have done this recently within the confines of the Blackbord Learn platform. I hope this code snippet helps you out:
Expand|Select|Wrap|Line Numbers
  1.     BufferedImage bi = ImageIO.read(new File(fullPathBase + imgSrc));
  2.         double currentWidth = bi.getWidth();
  3.         double currentHeight = bi.getHeight();
  4.         double displayHeight = 0;
  5.         double displayWidth = 0;
  6.         double ratio = 1.00;
  7.  
  8.         if(currentHeight > 150 || currentWidth > 150)
  9.         {
  10.             if(currentHeight >= currentWidth)
  11.             {
  12.                 ratio = currentHeight / 150 ;
  13.             }
  14.             else
  15.             {
  16.                 ratio = currentWidth /150;
  17.             }
  18.         }
  19.  
  20.         displayHeight = currentHeight / ratio;
  21.         displayWidth = currentWidth / ratio;
  22.         Double dEffectLeftPos = displayWidth - 4;
  23.         int effectLeftPos = dEffectLeftPos.intValue();
  24.  
  25.     %>
  26.  
  27.     <div id="esfWelcomeImgCont">
  28.     <img id="esfWelcomeImg" src="<%=imgSrc%>" height="<%=displayHeight %>" width="<%=displayWidth %>" title="<%=name%>" alt="<%=name%>" /></div>
  29.     <div id="esfWelcomeTxtCont" style="left:<%=effectLeftPos %>px">
  30.     <h3>Welcome to Compass</h3>
  31.     <p><%=name%></p>
  32.  
Note that the imgSrc variable has been set accordingly earlier in my application. Have look over the Java API for:
java.io.*
java.net.*
java.awt.image.BufferedImage
javax.imageio

This should see you right.
Hope it helps
nathj
Jan 6 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: André Næss | last post by:
Photoshop has a function called optimize to file size which tries to fit an image to some given file size. Because I need to make sure no images on a site I'm working on are larger than X KB I need...
9
by: Deepa | last post by:
Hi All, I'm facing problem displaying image of size 5000X5000 .My window size is smaller than image size so i'm not able to see the complete image.i can use scroll bars to view the image but i...
2
by: Jake | last post by:
Hi, I have a page with a bunch of thumbnails that when clicked, open the full size image in a new window. They are all different sizes and its a bit unprofessional looking. I'd like to find a...
1
by: timm.wong | last post by:
Hi, I have a program where I load images to a screen. How would I go about determining the size of an image prior to loading it on the screen? Thanks, Tim
6
by: ACaunter | last post by:
Hi there, I was wondering if there is a way to allow the user to resize an image by clicking and drawing on of the four corners of the image.. thanks -- AdamPC@hotmail.com
3
by: f.amann | last post by:
hi there! i save images in a mysql db and i wrote a script called getimage.php to display them. in my getimage.php i want to resize my images to display them as thumbnails but there always...
3
by: indhu | last post by:
hi all, i have problem in displaying image in my Picture column. even though i ve inserted the OLE unbound image control in the form Actually, images are stored in a folder. i have to fetch...
12
by: Speed | last post by:
Hi, Could you please tell me what is the simplest code to read a 8-bit grayscale JPEG using C++? Thanks a ton, Speed.
2
kamill
by: kamill | last post by:
Dear All, I am uploading a image file and after resize the image i am saving it. My script is working fine with small size images but when i am trying to upload big size image, i am getting below...
13
by: sevenz24 | last post by:
So i have my images set up like this : http://cgi.ebay.com/Tippmann-98-paintBall-Marker-Gun-Paint-Ball_W0QQitemZ250274334261QQihZ015QQcategoryZ47248QQssPageNameZWDVWQQrdZ1QQcmdZViewItem Scroll...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.