Zoom in , zoom out

Posted on 2006-04-28
Last Modified: 2010-04-01
I have a web application and that take information from sql server database using jdbc.  Into a table I have an image field.
I want to show this image in a jsp page and then use zoom in and zoom out to see the image and print in original size.
Someone can help me please?
Question by:olgavillamizar
    LVL 8

    Expert Comment

    To extract the image from the database you'll be best using a servlet instead of a jsp, as its all code with image output rather than text output (liek a jsp).

    You would then put links on your jsp to the servlet like this: <img src="MyImageServlet?id=1" />. This willcall the servlet called MyImageServlet, passing the paramater 1. The servlet will return the image extracted from the database.

    The zooming functionality is going to be a bit harder I think, cant help you with that sorry.

    LVL 8

    Expert Comment

    To zoom in and out you could change the height and width attribtes of the image html tag.

    So when a user clicks to zoom, you post the user to the same page, but with a parameter that says "zoom this". Your jsp would thens et the height and width of the image accordingly.

    LVL 27

    Accepted Solution

    colr  gave you a good start. Scaling can be done a number of ways  
    java.awt.geom.AffineTransform  has   scale(double sx,double sy)  
    java.awt.Image   has  getScaledInstance(int width,int height,int hints)
    Here is a method I had from before this.
         public static BufferedImage scale(BufferedImage bi){
             Image img = bi.getScaledInstance(100,-1,Image.SCALE_SMOOTH);
             int w = img.getWidth(null);
             int h = img.getHeight(null);
             BufferedImage scaled = new BufferedImage(w,h,BufferedImage.TYPE_INT_RGB);          
             Graphics2D g = scaled.createGraphics();
             if(g != null) g.dispose();
             return scaled;

    Show us your code and we will help you with it.   rrz
    LVL 27

    Expert Comment

    Here is something else I saw on this forum. I didn't try it yet.
    AffineTransform scale = AffineTransform.getScaleInstance(ratio, ratio);
    BufferedImage scaled = new BufferedImage(60, (int)(h*ratio), BufferedImage.TYPE_INT_RGB);
    Graphics2D g = scaled.createGraphics();
    g.drawImage(i, 0, 0, null);
    if(g != null) g.dispose();
    ImageIO.write(scaled, "JPG", thumbnailFile);
    LVL 1

    Author Comment

    Im going to probe it and i´l tell you

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Suggested Solutions

    Title # Comments Views Activity
    JspWriter.write() and JspWriter.print() 4 68
    Javamail API 3 128
    web service Rest Client creation 4 67
    gZip compression filter 2 73
    These days socially coordinated efforts have turned into a critical requirement for enterprises.
    Great sound, comfort and fit, excellent build quality, versatility, compatibility. These are just some of the many reasons for choosing a headset from Sennheiser.
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now