iOS Question takescreenshot method

le_toubib

Active Member
Licensed User
Longtime User
i m trying to take a screenshot using theis code :
B4X:
Dim no As NativeObject = Me
   Dim bmp As Bitmap = no.RunMethod("TakeScreenshot", Null)
   Log(bmp)
   ImageView1.Bitmap = bmp
but i get this error :

 

omidaghakhani1368

Well-Known Member
Licensed User
Longtime User
Hi.
You can use xcode inline code with below code
B4X:
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
    UIGraphicsBeginImageContextWithOptions(self.window.bounds.size, NO, [UIScreen mainScreen].scale);
else
    UIGraphicsBeginImageContext(self.window.bounds.size);

[self.window.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData * imgData = UIImagePNGRepresentation(image);
if(imgData)
    [imgData writeToFile:@"screenshot.png" atomically:YES];
else
    NSLog(@"error while taking screenshot");
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…