1

I have an image which is loaded into a quick map item, well I just want to find pixels row and column when user clicks on image, how can I get it? thanks

here is my code

MapQuickItem{
    id:yes
    anchorPoint.x: image.width/10
    anchorPoint.y: image.height/10
    zoomLevel:1
    //width: 1
    //height: 1
    sourceItem:  Image {
       id:image
       asynchronous:true
       opacity: 80
       source: "qrc:/../../../../../Desktop/1.png"
       transformOrigin: Item.Center
       rotation: 0
       scale: 0.25
       //width: 500
       //height: 200
       sourceSize.width: image.width/2
       visible: false
       //sourceSize.height:100
    }
    coordinate: QtPositioning.coordinate(59.91, 10.75)
}
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Majid Hojati
  • 1,740
  • 4
  • 29
  • 61
  • Do you want to get the pixel of the original image or the image shown? – eyllanesc Oct 13 '17 at 17:10
  • @eyllanesc do they have any differences? which one can I get? – Majid Hojati Oct 13 '17 at 17:11
  • If you notice in your code you have placed the following: sourceSize.width: image.width/2, So that image has been distorted. – eyllanesc Oct 13 '17 at 17:12
  • Do you want to get only the position of where you click or you want the colors too? If you want the position: what position do you require, that of the source or the visual? – eyllanesc Oct 13 '17 at 17:14
  • @eyllanesc I want the row and column of clicked pixel of source image, I dont need its colors yet. – Majid Hojati Oct 13 '17 at 17:19
  • You need the pixel position or you want the geographic position. The task you say is not simple. – eyllanesc Oct 13 '17 at 17:23
  • @eyllanesc I can get grographic position, but I want pixel position in image, which row and column it is located – Majid Hojati Oct 13 '17 at 17:25
  • If the size of the image they display does not match the actual size of the image is impossible since to be distorted a set of real pixels represent a single visual pixel or vice versa whether you have enlarged or reduced. – eyllanesc Oct 13 '17 at 17:26
  • For example let's say that the image is originally 400 * 400 but I show it as a 10 * 10 image, then 1 pixel of the visual image corresponds to 40 * 40 of the original image. – eyllanesc Oct 13 '17 at 17:27
  • @eyllanesc well, so first of all we must show image in real size right?well how can we get clicked pixel location when it is show in real size? – Majid Hojati Oct 13 '17 at 17:33
  • add: `MouseArea{ anchors.fill: parent onPressed: { console.log(mouse.x + " "+ mouse.y) } }` inside of Image – eyllanesc Oct 13 '17 at 17:35
  • @eyllanesc thanks, but it seems it does not return pixel row and column as they are integer values, it returns double values. – Majid Hojati Oct 13 '17 at 17:52
  • Are you sure? I get the following: `qml: 237 113 qml: 101 92 qml: 100 105 qml: 98 111 qml: 154 111 qml: 213 111 qml: 125 107` – eyllanesc Oct 13 '17 at 17:54
  • @eyllanesc yes, I don't know why this is happening, can you share your code?So I can try with yours – Majid Hojati Oct 13 '17 at 18:07
  • @eyllanesc this is one example of output qml: 300.69747172264204 181.14527650058574 – Majid Hojati Oct 13 '17 at 18:07
  • Share your code through github or gist to see what the error is. – eyllanesc Oct 13 '17 at 18:09
  • @eyllanesc here you are:https://gist.github.com/am2222/057af8eb729a76b4f09c818de1d0ad24 – Majid Hojati Oct 13 '17 at 18:15
  • Instead of adding inside the Image add it inside MapQuickItem. – eyllanesc Oct 13 '17 at 18:26
  • @eyllanesc it seems it is not returning images pixel location. it is returning sth else. As When I click outside of image it also returns a value – Majid Hojati Oct 13 '17 at 18:32
  • @eyllanesc it seems putting MouseArea in Image tag works, I just have to round its value – Majid Hojati Oct 13 '17 at 19:01

0 Answers0