Pixelcolor Path

Is there a way to check the color of the pixels along a path?

Var p As New iOSPath
p.MoveToPoint(sx, sy) // Start location
p.LineToPoint(xendpos, yendpos)

g.LineColor = Color.Blue

Still struggling with this, how do we get a pixel color in IOS?

I was thinking on this line but graphics.pixel doesn’t exist. I am trying to draw a path of points along a line but before drawing each point check the color, if it is black it is out of bounds.

Dim c as Color
c = map3.Graphics.Pixel(xendpos, Yxendpos)
if c <> color.RGB(0,0,0) then
Var p As New iOSPath
p.MoveToPoint(sx, sy) // Start location
p.LineToPoint(xendpos, yendpos)

g.LineColor = Color.Blue
end if

This simple thing is why I abandoned an iOS project written in Corona, AND one written in Xojo, (which naively I imagined would have such a feature).
I can do it using another tool now, but don’t understand why it is missing from Xojo iOS after all these years.

1 Like

Assuming what I was requesting can’t be done what would my approach be to move an object around the canvas only on the blue areas?

Martin I will work on this as I will need this in a project we are about to start also. Give me some time but I’ll see what I can come up with.

Thanks Mike, I wrote it a long time ago in Future Basic and thought it would be relatively simple with Xojo give all the fancy hooks it has, so there has to be something in there to cover it :slight_smile: Appreciate the help.

1 Like

Consider the image as a map of discrete squares, equivalent to (say) 10x 10 or maybe smaller pixels.
Internally, represent that as a an array of uint8s

Where x,y is not blue, store 1 in the array.
Then you can start at any blue x,y position, and consider travel to any of the 8 adjacent ‘squares’ if they also contain ‘0’

This only works if the image is known in advance of course.
You cant do that if you are being presented with an actual map photo and trying to sail around an island.

1 Like

I had some code that worked for 32 bit to do this. Search the forum and you should find it. I think it needs to be updated for 64bit but that shouldn’t be a terrible amount of work


Thanks Jason, found it and still works.

1 Like

Since I can’t get pixelcolor to work in IOS and the map is complicated would I have to create a map generator in Desktop using RGBsurface to do as you say and make a big array map. Export that out and then in IOS import that… but that won’t work for scaled images on each device… hmm half a thought.

I’m not familiar with declares and the following seems to find the pixel color accurately in one of my views, but if I rotate the device or change to iPhone it doesn’t. I call it in the paint event with
b= new iOSBitmap(canvas1.width,canvas1.height,1.0)
c = b.Graphics.Pixel(sx,sy)

Any suggestions?

const UIKitLib = “UIKit.framework”
const CoreGraphicsLib = “CoreGraphics.framework”
const FoundationLib = “Foundation.framework”

declare function CGBitmapContextCreateImage lib CoreGraphicsLib (context as ptr) as ptr
dim cgimageref as ptr = CGBitmapContextCreateImage(g.Handle)

declare function imageWithCGImage lib UIKitLib selector “imageWithCGImage:” (clsRef as ptr, img as ptr) as ptr
declare function NSClassFromString lib FoundationLib (clsName as CFStringRef) as ptr
dim newUIImage as ptr = imageWithCGImage(NSClassFromString(“UIImage”), cgimageref)

Return iOSImage.FromHandle(newUIImage).Pixel(x,y)

Still playing with the following findings

  • It works on an actual iPad in both orientations but in the simulator only in Portrait
  • Definitely doesn’t work in either orientation on iPhones in the simulator or real device.
    Is it a 64bit issue?

The original code was written in 2014 for 32bit when there was no 2x or 3x scaling. It’s quite possible (likely even) that you will need to update it for 64bit and scaling resolutions

I guess we will have to put the project aside and wait for a Xojo release as that would be above my pay grade to attempt :slight_smile:

Just added a feedback case for Canvas Pixel Color

61881 - IOS Pixel Color


should rather be
declare function imageWithCGImage lib UIKitLib selector "imageWithCGImage:scale:orientation:" (clsRef as ptr, img as ptr, scale as CGFloat, orientation as Integer) As Ptr

with orientation being a value from [this list].(https://developer.apple.com/documentation/uikit/uiimage/orientation)

Thanks @Ulrich_Bogun but I don’t fully understand Declares yet. Plugging this line in causes
dim newUIImage as ptr = imageWithCGImage(NSClassFromString(“UIImage”), cgimageref)
to complain about not enough parameters

Yes. You need to define both new input parameters. Make that

dim newUIImage as ptr = imageWithCGImage(NSClassFromString(“UIImage”), cgimageref, ScaleFactor, 0)

(ScaleFactor according to your device 1, 2 or 3)
The 0 is taken from the list above – standard orientation.

EDIT: You can imagine a declare like being the head of a method. So you have to feed the input parameters and take care of the result in case of a function. Only the method itself is executed inside the API into which you declared.

Hi Ulrich,
That makes a bit more sense but I can’t grasp the parameters example below


I haven’t done anything in Xojo iOS for years, Martin. Can you help me remember where to read the scalefactor of an iOS device in Xojo?
Also, there seems to be no way to get the orientation of an iOSImage. Could be possible there are even more declares necessary to get the data.