473,396 Members | 2,039 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,396 software developers and data experts.

Take coordinates form image

Hello,
I have a simple problem: mark a list of defects
on an image.

I think the best way to do it is to select a single
deffect, then take two coordinates of coursor
form an image on a web page (first when user press
the button, and the second when he releases it).
Those two points are going to be send to the web
application (i.e. with AJAX) and saved in a database.
Later, I will use those points to render
the image with RMagic (drawing the lines and defects
list numbers on top of the image).

Any suggestions how to do it?

Even a chapter in a book, or enything
what could get me started is welcomed.

Best regards,
Tom
Nov 23 '05 #1
4 2416
"Tomasz Bak" <op*******@wp.pl> wrote in message
news:dl**********@nemesis.news.tpi.pl...
Hello,
I have a simple problem: mark a list of defects
on an image.

I think the best way to do it is to select a single
deffect, then take two coordinates of coursor
form an image on a web page (first when user press
the button, and the second when he releases it).
Those two points are going to be send to the web
application (i.e. with AJAX) and saved in a database.
Later, I will use those points to render
the image with RMagic (drawing the lines and defects
list numbers on top of the image).

Any suggestions how to do it?

Even a chapter in a book, or enything
what could get me started is welcomed.

Best regards,
Tom


Will this help? Watch for word-wrap.

<html>
<head>
<title>coords.htm</title>
<script type="text/javascript">
function coords() {
var f = document.forms[0];
var x = window.event.screenX;
var y = window.event.screenY;
if (f.xy1.value == "") {
f.xy1.value = x + "," + y;
} else {
f.xy2.value = x + "," + y;
}
}
</script>
</head>
<body>
<img src="http://www.google.com/intl/en/images/logo.gif"
border="1" width="276" height="110" alt="" onclick="coords()">
<form>
<br><input type="text" name="xy1" size="9" value="">
<br><input type="text" name="xy2" size="9" value="">
<br><input type="reset" value="Reset">
</form>
</body>
</html>
Nov 23 '05 #2
McKirahan wrote:
"Tomasz Bak" <op*******@wp.pl> wrote in message
news:dl**********@nemesis.news.tpi.pl...
Hello,
I have a simple problem: mark a list of defects
on an image.

I think the best way to do it is to select a single
deffect, then take two coordinates of coursor
form an image on a web page (first when user press
the button, and the second when he releases it).
Those two points are going to be send to the web
application (i.e. with AJAX) and saved in a database.
Later, I will use those points to render
the image with RMagic (drawing the lines and defects
list numbers on top of the image).

Any suggestions how to do it?

Even a chapter in a book, or enything
what could get me started is welcomed.

Best regards,
Tom

Will this help? Watch for word-wrap.


If the solution is only for browsers implementing the IE event model and
window properties, and if the position is to be relative to the entire
screen, then yes.

But if the solution needs to be cross-browser and the coordinates
relative to the image, the script below may suit better. Note that IE
does not include the default body padding/margin in the offset, so it
must be set to some value (say zero) or the element absolutely
positioned - otherwise the coordinates will be out by whatever the IE
default is (about left 13px and top 17px).

The following script it a quick hack from bits I had lying around: it
will only draw a box from top left to bottom right; boxes can extend
beyond the image; event capturing and handling is probably not optimal
(well, almost certainly not); /et al/.

Quite a bit of further development is required but it gives the OP some
idea of the scope of what is being attempted.
<div id="mBox" style="position: absolute; border: 2px solid red;
display: none;"></div>

<img src="a.jpg"
border="1" width="276" height="110" alt=""
onmousedown="DoMeasure.startMeasure(event, this)"
style="position: absolute; top: 100px; left: 100px;"><br>
<input type="button" value="Clear boxes"
onclick="DoMeasure.clearBoxes();">
<div id="msg"></div>

<script type="text/javascript">

var DoMeasure = ( function() {

var mBoxRoot = document.getElementById('mBox');
var Boxes = [];
var msgDiv = document.getElementById('msg');
var docBody = document.body || document.documentElement;

function startMeasure(e, el)
{
var cPos = getCursorPos(e);
var box = mBoxRoot.cloneNode(true);
Boxes[Boxes.length] = box;
box.style.display = '';
box.id = '';
box.style.left = cPos.x + 'px';
box.style.top = cPos.y + 'px';
docBody.appendChild(box);

var elPos = getElPos(el);

el.onmousemove = function() {stretchBox(e, cPos, box);}
el.onmouseup = stopMeasure;

// Event capture not need for 'zillas but important for IE
if ( el.captureEvents ) { // Capture events 'zillas
el.captureEvents(
Event.MouseDown | Event.MouseMove | Event.MouseUp
);
} else if ( el.setCapture ) { // Capture events IE
el.setCapture();
}

// Just for debug
msgDiv.innerHTML = (cPos.x - elPos.x)+', '+(cPos.y - elPos.y);
}

// Return the position of event (cursor)
function getCursorPos(e)
{
if (e.pageX || e.pageY) return {x:e.pageX, y:e.pageY};
if (e.clientX || e.clientY) {
return {x:e.clientX + document.body.scrollLeft,
y:e.clientY + document.body.scrollTop};
}
}

// Return the top left position of an element
function getElPos(el)
{
var pos = {x:0, y:0};
if (el.offsetParent){
while (el.offsetParent){
pos.x += el.offsetLeft;
pos.y += el.offsetTop;
el = el.offsetParent;
}
return pos;
}
if (el.x) return {x:el.x, y:el.y}
}

// Change the width & height of an element
function stretchBox(e, sPos, box)
{
var e = e || window.event;
var cPos = getCursorPos(e);
box.style.width = (cPos.x - sPos.x) + 'px';
box.style.height = (cPos.y - sPos.y) + 'px';
}

// Cancel mousemove & cleanup
function stopMeasure(e)
{
var e = e || window.event;
this.onmousemove = null;

if ( this.releaseEvents ) { // Release events & capture
this.releaseEvents(
Event.MouseDown | Event.MouseMove | Event.MouseUp
);
} else if ( this.releaseCapture ) {
this.releaseCapture();
}

var cPos = getCursorPos(e);
msgDiv.innerHTML += '<br>' + cPos.x + ', ' + cPos.y;
}

return ({

// Start measuring on mousedown
startMeasure :
function(e, el){
var e = e || window.event;
startMeasure(e, el);
},

// Delete measurement boxes
clearBoxes :
function(){
var i = Boxes.length;
while(i--) Boxes[i].parentNode.removeChild(Boxes[i]);
Boxes.length = 0;
}
});
})();
</script>

--
Rob
Nov 23 '05 #3
RobG wrote:
McKirahan wrote:
"Tomasz Bak" <op*******@wp.pl> wrote in message
news:dl**********@nemesis.news.tpi.pl...

Even a chapter in a book, or enything
what could get me started is welcomed.

Best regards,
Tom
Will this help? Watch for word-wrap. Thank you, it helps a lot to see a solution
in just a couple of lines!


If the solution is only for browsers implementing the IE event model and
window properties, and if the position is to be relative to the entire
screen, then yes.

Supporting other browsers is a good thing.
Especially as long as I dont use IE myself ;P

But if the solution needs to be cross-browser and the coordinates
relative to the image, the script below may suit better. Note that IE
does not include the default body padding/margin in the offset, so it
must be set to some value (say zero) or the element absolutely
positioned - otherwise the coordinates will be out by whatever the IE
default is (about left 13px and top 17px). Oki. I think I can open the image in another window
(there is some javascript call to open a popup I believe)
and the problem with relativness will disappear.

The following script it a quick hack from bits I had lying around: it
will only draw a box from top left to bottom right; boxes can extend
beyond the image; event capturing and handling is probably not optimal
(well, almost certainly not); /et al/.

Thats more than enough to get me going. Thanks!

Best regards,
Tom
Nov 23 '05 #4
On 2005-11-20, Tomasz Bak <op*******@wp.pl> wrote:
Hello,
I have a simple problem: mark a list of defects
on an image.

I think the best way to do it is to select a single
deffect, then take two coordinates of coursor
form an image on a web page (first when user press
the button, and the second when he releases it).
Those two points are going to be send to the web
application (i.e. with AJAX) and saved in a database.
Later, I will use those points to render
the image with RMagic (drawing the lines and defects
list numbers on top of the image).

Any suggestions how to do it?


capture the onmousedown and onmouseup events and extract the
coodinates from them (possibly subtracting the images left and top
coodinates to get a result relative to the image.

--

Bye.
Jasen
Nov 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Tony Gahlinger | last post by:
I'm using my browser (Mozilla/5.0 Linux i686 Gecko/20031007 Firebird/0.7) to do some client-side image processing. I want to capture the sequence of coordinates a user clicks on in xxx.jpg in the...
3
by: Tom | last post by:
I have a picturebox on my VB.NET form. The picturebox size mode is set to stretched. I then load an image into that form and display it. As the user moves the mouse over the form, I want to get and...
0
by: deko | last post by:
I'm trying to implement a custom TreeView that shows a ghost image while dragging. But the form I'm using is different from the sample code found here:...
1
by: emferrari | last post by:
Hi all I'm developing a windows form application that has a picturebox in which I'll load screen prints from a jpg file. I want the user to click in one point in the image and after the click...
8
by: Bob Bedford | last post by:
Hello, I've some geographical coordinates and I'd like to put them on a map. Example: I've the map of the USA. Once I've selected Chicago, I'd like a point-cross or what ever, on the Chicago...
0
by: nupur.agarwal29 | last post by:
Hi All, I have a web browse control hosted in a windows form. I want to calculate the coordinates of all the images present in the web page displayed in the webbrowser. I am adding all the...
3
by: jackiepatti | last post by:
QUESTION: I have a web page containing a form that contains an image instead of a submit button, e.g. <form name='myform' action='get' method='otherpage.asp'> <input type='image'...
3
by: Andrzej | last post by:
I have a picturebox on my C# .NET form. The picturebox size mode is set to zoom. I then load an image into that form and display it. As the user moves the mouse over the form, I want to get and...
1
by: Cainnech | last post by:
Hi all, I've got a bit of a challenge. I've got a script which displays the mouse coodinates if you click on an image. Now I would like to convert these coordinates to pixelnumber. Let me see if I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.