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 :

Application_Start
Application_Active
Error occurred on line: 1622 (main)
Method not found: TakeScreenshot, target: <b4i_main: (null)>
Stack Trace: (
CoreFoundation <redacted> + 150
libobjc.A.dylib objc_exception_throw + 38
CoreFoundation <redacted> + 0
مقياس سناب +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 426
مقياس سناب -[B4INativeObject RunMethod::] + 164
مقياس سناب -[b4i_main _imgrt_click] + 352
CoreFoundation <redacted> + 68
CoreFoundation <redacted> + 300
مقياس سناب +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1788
مقياس سناب -[B4IShell runMethod:] + 496
مقياس سناب -[B4IShell raiseEventImpl:method:args::] + 1768
مقياس سناب -[B4IShellBI raiseEvent:event:params:] + 1332
مقياس سناب __33-[B4I raiseUIEvent:event:params:]_block_invoke + 74
libdispatch.dylib <redacted> + 10
libdispatch.dylib <redacted> + 22
libdispatch.dylib <redacted> + 1322
CoreFoundation <redacted> + 8
CoreFoundation <redacted> + 1512
CoreFoundation CFRunLoopRunSpecific + 476
CoreFoundation CFRunLoopRunInMode + 106
GraphicsServices GSEventRunModal + 136
UIKit UIApplicationMain + 1440
مقياس سناب main + 108
libdyld.dylib <redacted> + 2
)
 

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
Top