Your question doesn’t make sense with the code you posted. You are requesting the pixel from an image (tmpImg), which is not related to the screen. If you were to somehow capture the contents of the screen into an image, you could use that image to examine the screen pixel. If you just want to get the info of what is in a JUCE Component you can use this API:
Image Component::createComponentSnapshot(Rectangle< int > areaToGrab, bool clipImageToComponentBounds=true, float scaleFactor=1.0f)
If you want to grab things outside of your application, then you will need to do something else, which is indicated at the end of this thread:
Right, it did not make sense indeed. The fact is that I made a shortcut for the code and forgot to mention the following: tmpImg is a global variable and in the original code, outside from the paint override, I was using another Graphics object for allowing me to use fillEllipse(). But while this image was properly rendered, using g.drawImage(tmpImg) in paint(), I could not get any pixel from it. Which probably leads us to some other nonsense issue?
The tmpImg is not going to change based on what you do in the Component’s paint() code. What you see on the screen is a separate pixel buffer, your image drawn before is drawn into that. If you really need to be able to get pixels from what is visible on the screen in the component, you may need to do tricks like capture an area of the component as a new Image like cpr suggested above. (And depending how often you would need to do that, it could get pretty inefficient…)
Thanks a lot. My problem might be different (and I hope it is): to sum up, I want to get pixels from an Image on which has been drawn a path with fillEllipse().
I’m a bit confused with this.
Because I’m using another Graphic context: Graphics lg (tmpImg), then I’m using fillEllipse() there, and call repaint().
Therefore in paint(), if i call g.drawImage(tmpImg, 0, 0, 600, 400, 0, 0, 600, 400);
it is effectively painted. So I suppose the image exists there…
But I can’t get pixel data from it.
Sorry, I messed around with the variables in my DBG line.
I could finally obtain the getPixelAt() working from my image.
Though it might not been necessary for me to call getPixelAt() in another place, that’s what I did ( and in the paint() method! ) . I am still not sure why I can’t get getPixelAt working outside the function where I drew it, but I’ll investigate on this, Thank you.