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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • yadagereavinash
    New Member
    • Dec 2010
    • 7

    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...
    Last edited by Niheel; Jan 10 '11, 12:25 AM. Reason: Please don't beg, there's a lot of people on the site that need questions answered.
  • nathj
    Recognized Expert Contributor
    • May 2007
    • 937

    #2
    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:
    Code:
    	BufferedImage bi = ImageIO.read(new File(fullPathBase + imgSrc));
    		double currentWidth = bi.getWidth();
    		double currentHeight = bi.getHeight();
    		double displayHeight = 0;
    		double displayWidth = 0;
    		double ratio = 1.00;
    		
    		if(currentHeight > 150 || currentWidth > 150)
    		{
    			if(currentHeight >= currentWidth)
    			{
    				ratio = currentHeight / 150 ;
    			}
    			else
    			{
    				ratio = currentWidth /150;
    			}
    		}
    		
    		displayHeight = currentHeight / ratio;
    		displayWidth = currentWidth / ratio;
    		Double dEffectLeftPos = displayWidth - 4;
    		int effectLeftPos = dEffectLeftPos.intValue();
    		
    	%>
    	
    	<div id="esfWelcomeImgCont">
    	<img id="esfWelcomeImg" src="<%=imgSrc%>" height="<%=displayHeight %>" width="<%=displayWidth %>" title="<%=name%>" alt="<%=name%>" /></div>
    	<div id="esfWelcomeTxtCont" style="left:<%=effectLeftPos %>px">
    	<h3>Welcome to Compass</h3>
    	<p><%=name%></p>
    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

    Comment

    Working...