Cropped Screenshot

Is there a way to grab a cropped screenshot or just the screen area?

In the Simulator, no. On a Mac, Cmd-Shift-4. On iOS, I haven’t heard of any.

From within your app i meant to say.

Did you try the Screenshot function in iOSKit?

https://github.com/kingj5/iOSKit/blob/master/Modules/Extensions.xojo_code#L412

Yes I found that after my initial post which works well
Mypic.Graphics.DrawImage(self.ScreenShot,30,260,600,800)
which grabs the whole screen but wanting below and above the layout guides. Actually what would be even better for this task would be to add the current iostable on screen to a iosimage which I guess is what I am trying to do with the screen shot

If I am printing the screenshot, what process would give me the best resolution on the printout?

The current output looks a little fuzzy.

Dim Mypic As New iOSBitmap(600,800, 1.0, False)
Mypic.Graphics.DrawImage(self.ScreenShot,20,10,560,800)

The current implementation of the Screenshot function by Jason King grabs the whole screen (UIWindow).

If you are experienced with declares I am sure you can make your own function that will only grab a specific control (the iOSTable for example).
If you aren’t experienced with this, I will look into it this evening (European time, next morning for you)

[code]Public Function ScreenShotXC(extends aControl as iOSControl, Retina as Boolean = False) as iOSImage
//Mod of Jason King’s ScreenShot function from iOSKit

Declare Function mainScreen Lib UIKitLib selector "mainScreen" (clsRef As ptr) As ptr

declare function bounds lib UIKitLib selector "bounds" (obj_id as Ptr) as CGRect64



dim sz as CGSize64 = bounds(aControl.handle).rsize


If not Retina then
  
  declare sub UIGraphicsBeginImageContext lib UIKitLib (mSize as CGSize64)
  
  UIGraphicsBeginImageContext(sz)
  
Else
  
  
  declare sub UIGraphicsBeginImageContextWithOptions lib UIKitLib (mSize as CGSize64, opaque as boolean, scale as double)
  
  UIGraphicsBeginImageContextWithOptions(sz, true, 0.0) //0.0 uses current screen scale
End If


dim viewRef as ptr = (aControl.handle)


declare function layer lib UIKitLib selector "layer" (obj_id as ptr) as ptr
declare sub renderInContext lib UIKitLib selector "renderInContext:" (obj_id as ptr, ctx as ptr)
declare function UIGraphicsGetCurrentContext lib UIKitLib () as ptr
renderInContext(layer(viewRef), UIGraphicsGetCurrentContext)

declare function UIGraphicsGetImageFromCurrentImageContext lib UIKitLib () as ptr
dim newUIImage as Ptr = UIGraphicsGetImageFromCurrentImageContext

declare sub UIGraphicsEndImageContext lib UIKitLib ()
UIGraphicsEndImageContext

Return iOSImage.FromHandle(newUIImage)

End Function
[/code]

Thanks Jeremie, I am the later :slight_smile:

Hi Jeremie,
just wanted to say an extra thank you and let you know how useful that Control element screenshot is… great time saver and extension of Jason’s work (which is also amazing).
Martin