Android Question Get pixel information from screen, not bitmap?

Mark Read

Well-Known Member
Licensed User
Longtime User
Is it possible to get the pixel information, RGB values etc from the screen directly without making a screenshot and reading the bitmap?

I found this java code which seems to do the job but cannot convert it to ba4.

B4X:
public static Color getColorAt(int x, int y){
   return new Robot().getPixelColor(x, y);
}

Can anyone help or is this possible?
 

Mark Read

Well-Known Member
Licensed User
Longtime User
Thank you for the rather short reply Erel. Is there another way?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Make a Screenshot and geht the pixel fron this imahe
 
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
Thanks Manfred, that is what I am doing at present and its works but slowly. I have also found that a screenshot is device dependent ie. The pixel information for the same point on my mobile is not the same as on my tablet (the RGB values are different). I am working on a way to calibrate the system but I had hoped for a more direct approach, reading the screen in the hope that this problem would be fixed. I am not even sure why there is a difference in the bitmaps. I have probably overlooked something.
 
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
How very true. At present, the App is designed for a 10" tablet with resolution 1200 x 800 (roughly) and have to process up to 500 pixels at semi-random positions. I can find no way to speed this up. I had wondered about using a class or a thread but that is beyond my knowledge at present and I am not sure if it would even help.
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Would it be quicker to first establish witch pixel(s) you want to verify and then capture only that pixel instead of the hole screen?
 
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
Unfortunately not, as I am calculating a route between two pixel points (eg. top left to bottom right along a river) and they can be anywhere on the screen.
 
Upvote 0

NeoTechni

Well-Known Member
Licensed User
Longtime User
It'd be possible if it was your app it was getting it from, not the screen itself. Then you'd just get it from the canvas
 
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
@NeoTechni: Now I am curious. It is my app. I am using OSMdroid and have a map on the screen. Using overlays and the touch event, I generate two markers. Then I calculate the route between these two markers. I know the exact position of the markers. How does a canvas help me here?
 
Upvote 0
Top