473,382 Members | 1,425 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,382 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 1543
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: 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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.