zoom In/zoom Out an Image

Discussion in 'Java' started by dwurity@gmail.com, Feb 14, 2005.

  1. Guest

    Hi
    I am developing an applet application, and placed an Image,when a
    button(zoom In) click ,I have to perform the zoom In function .....

    How can I do that...

    Thanks in advance,
    dwurity
     
    , Feb 14, 2005
    #1
    1. Advertising

  2. Keith James Guest

    >>>>> "dwurity" == dwurity <> writes:

    dwurity> Hi I am developing an applet application, and placed an
    dwurity> Image,when a button(zoom In) click ,I have to perform the
    dwurity> zoom In function .....

    dwurity> How can I do that...

    e.g. using a JPanel, override paintComponent:

    protected void paintComponent(Graphics g)
    {
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D) g.create();

    AffineTransform transform = new AffineTransform();
    Insets insets = getInsets();
    transform.translate(insets.left, insets.top);

    // Implement a getScale() method which returns your current scale
    double scale = getScale();

    // Assumes you want to scale equally on x and y axes
    transform.scale(scale, scale);
    g2.transform(transform);

    // Implement a getImage() method which returns your current Image
    Image image = getImage();

    if (null != image)
    {
    g2.drawImage(image, 0, 0, this);
    }

    g2.dispose();
    }

    That's one way to do it - then just hook up your button to a setter to
    a method setScale(double scale) which changes the scale value.

    --

    - Keith James <> - Human Genetics Informatics -
    - The Wellcome Trust Sanger Institute, Hinxton, Cambridge, UK -
     
    Keith James, Feb 14, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    538
    jfalt
    Feb 15, 2005
  2. Replies:
    0
    Views:
    424
  3. Replies:
    0
    Views:
    341
  4. Replies:
    2
    Views:
    869
  5. Miguel Ángel Esbrí

    How to zoom in and out an image?

    Miguel Ángel Esbrí, Jul 3, 2003, in forum: ASP .Net Mobile
    Replies:
    0
    Views:
    162
    Miguel Ángel Esbrí
    Jul 3, 2003
Loading...

Share This Page