iOS Code Snippet geting screenshot

tufanv

Expert
Licensed User
Hello,

Is it possible to get the screenshot within the application's first stage and send it to a server on the other stage?

second part is to do something with the httputils i think but the important one is first part. Can i take a screenshot without saving into users phone and just send it to a server and then just delete it ?

Thank you
 

Erel

Administrator
Staff member
Licensed User
B4X:
Sub Page1_Click
   Dim no As NativeObject = Me
   Dim bmp As Bitmap = no.RunMethod("TakeScreenshot", Null)
   Log(bmp)
   ImageView1.Bitmap = bmp
End Sub

#If OBJC
- (UIImage*) TakeScreenshot {
    UIView *view = [[UIApplication sharedApplication] keyWindow];
  float scale = [[UIScreen mainScreen] scale];
  CGRect bounds = [[UIApplication sharedApplication] keyWindow].rootViewController.view.bounds;
  BOOL shouldRotate = ([[[UIDevice currentDevice] systemVersion] floatValue] < 8.0f && bounds.size.width >= bounds.size.height);
  CGSize size = shouldRotate ? CGSizeMake(view.bounds.size.height, view.bounds.size.width) : view.bounds.size;

  UIGraphicsBeginImageContextWithOptions(size, YES, scale);
  CGContextRef ref = UIGraphicsGetCurrentContext();
  UIBezierPath *path = [UIBezierPath bezierPathWithRect:bounds];
  [[UIColor whiteColor] setFill];
  [path fillWithBlendMode:kCGBlendModeNormal alpha:1];
  if (shouldRotate) {

  CGContextConcatCTM(ref, CGAffineTransformMakeRotation((CGFloat) -M_PI_2));
  CGContextConcatCTM(ref, CGAffineTransformMakeTranslation(-size.height, 0));
  }
  [view drawViewHierarchyInRect:CGRectMake(0, 0, view.bounds.size.width, view.bounds.size.height) afterScreenUpdates:false];
  UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
  UIGraphicsEndImageContext();
  return image;
}
#End If
 
Top