Solved

code for displaying an image and identifying clicks on it

Posted on 2001-06-07
10
224 Views
Last Modified: 2010-08-05
hi.

i need - URGENTLY - a specific code for displaying an image and mapping a click on it.

i need to diaplay teh image on screen, identify the clicks of the user upon it, and map the location of the click (pixel?coordinates?ideas?).

the more specific the code the better.

thanks for your help, Adih
0
Comment
Question by:Adih
  • 5
  • 2
  • 2
  • +1
10 Comments
 
LVL 1

Accepted Solution

by:
eattrig earned 150 total points
ID: 6164233
import javax.swing.*;
import java.awt.event.*;

public class ClickPoint extends JDialog
{
    public ClickPoint()
    {
        Icon image = new ImageIcon("yourImage.gif");
        JLabel label = new JLabel(image);
        label.setSize(image.getIconWidth(), image.getIconHeight());
        label.addMouseListener
        (
            new MouseAdapter()
            {
                public void mouseClicked(MouseEvent e)
                {
                    System.out.println(e.getPoint());
                }
            }
        );
        this.setSize(image.getIconWidth(), image.getIconHeight() + 30);
        this.getContentPane().setLayout(null);
        this.getContentPane().add(label);
        this.setVisible(true);
    }

    public static void main(String[] args)
    {
        ClickPoint c = new ClickPoint();
    }
}


Is this what you wanted???  This will output the point which has been clicked.
0
 
LVL 2

Author Comment

by:Adih
ID: 6164412
please dont lock the question by answering but give chances to every1 to see it.

maybe i didnt explain myself.

i need to MAP the clicks.

i need to turn to the same spot on another bitmap to retreive information.

the coordinate system can work if i knew how to access the bitmap using it.

Adih
0
 
LVL 2

Author Comment

by:Adih
ID: 6164502
eattrig:
i used the code given and accessed the gif and retreived the coordinates required, now-
I NEED TO GET THE VALUE OF A PIXEL FROM ANOTHER GIF AT THOSE COORDINATES.

please issue a code to do that and the A grade of 300 pts is yours.
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 1

Expert Comment

by:eattrig
ID: 6164966
what type of information do you need to get from the other bitmap?
0
 
LVL 2

Author Comment

by:Adih
ID: 6165105
each pixel at the gif is colored in a specific value.

i need to extract that value.

if a user clicked on the map at (12,34) i need to retreive the color of the pixel at those coordinates at the other gif.

adih
0
 
LVL 92

Expert Comment

by:objects
ID: 6172410
You need to use the PixelGrabber class to extract the pixel values. Let me know if you need some help with it.
0
 
LVL 2

Author Comment

by:Adih
ID: 6172875
i never used that class and this is VERY urgent, so i would appreciate some specific code on extracting the pixel value at a apecific (x,y) coordinates.

the question is not so hard, but since it is URGENT i gave it 300 pts!

please be quick with the answer, and u shall be rewarded.

adi.
0
 
LVL 92

Expert Comment

by:objects
ID: 6172908
adi,

I'm just about to knock off for the day but here goes:

i is the image
w is the image width
x,y is the location of the pixel of interest

int pixels[] = new int[1];
PixelGrabber pg = new PixelGrabber(i, x, y, 1, 1, pixels, 0, w);
pg.grabPixels();
if ((pg.getStatus() & ImageObserver.ABORT) == 0)
{
  // The value of the pixel should now be in pixels[0]
}

You can use this to grab any rectangular region out of the image, placing the pixel data into the pixels array.

Sorry I can't hang around to help you further but you should be right. Check the javadoc for PixelGrabber if you're confused about anything. ANd I think it's also covered in Sun's Java tutorial.

I'll check how you went in the morning.


0
 

Expert Comment

by:teacher_mod
ID: 6173530
I have reduce to points to 150 to enable a split.

teacher_mod
Community Support Moderator
Experts-Exchange
teacher_mod@experts-exchange.com
0
 
LVL 2

Author Comment

by:Adih
ID: 6173955
thanks guys.

with ur answers combined i managed to solve the prob.

150 pts for eattrig - grade A
150 pts for objects will be awarded in a new 150 pts question:
http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=java&qid=20132788

thank u, Adih
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Should localization be done inside spring controller 5 32
more than one jdk and one jre 1 50
JavaFX TableView not displaying correctly 3 58
jboss 7.1 start up error 1 40
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

829 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