Pixelcolor Path

From a previous post I found that all common devices today are 2x except the iPhone 6 Plus which is 3x. But iPad mini and iPad 2 are still pretty common and are 1x devices.

I couldn’t find anything on the actual image orientation but device orientation is determined as follows

If Self.Size.Height > Self.Size.Width Then
// Landscape
End If

If Self.Size.Height < Self.Size.Width Then
// Portrait
End If

I’m trying to track down a pair of declares for the scalefactor 32/64

ScaleFactor is a property of UIScreen which should be iOSScreen in Xojo.
Declare function getScale lib UIKit selector "scale" (id as ptr) as CGFloat
And in your call to CGImage
dim newUIImage as ptr = imageWithCGImage(NSClassFromString(“UIImage”), cgimageref, getScale(App.CurrentScreen.handle), 0)

Other values for orientation are (upside)down = 1, left = 2, right = 3

Is this meant to be UIKitLib?

Declare function getScale lib UIKit selector “scale” (id as ptr) as CGFloat

Also App crashes with this call


I can get the scale with the following

Declare Function NSClassFromString Lib “Foundation” (aClassName As CFStringRef) As Ptr
Declare Function scale Lib “Foundation” Selector “scale” (classRef As Ptr) As CGFloat
Declare Function mainScreen Lib “Foundation” Selector “mainScreen” (classRef As Ptr) As Ptr

Return scale(mainScreen(NSClassFromString(“UIScreen”)))

and plug that into your amendment to newUIImage but it still returns the wrong colours

Can you give more details than “wrong colors”? Is it off by a scale factor, off by a rotation, something else? Find the color you get from the function to the image and you’ll be able to figure out what logic you need to change to fix it

1 Like

Hi Jason,

I think this calc is probably returning the wrong value as I pass the pointer over the color stripes horizontally in the example I posted (your example modified) the color seems to be offset by about 10% of the screen width. I haven’t worked out what is going on vertically yet

dim numberOfComponents as Integer = 4 //PNG is RGBA
dim startPoint as Integer = (img.Width*y)+x)*numberOfComponents

dim r, g, b, a as UInt8
b = dataMB.UInt8Value(startPoint)
g = dataMB.UInt8Value(startPoint+1)
r = dataMB.UInt8Value(startPoint+2)
a = 255-dataMB.UInt8Value(startPoint+3)