iOS Code Snippet geting screenshot

Discussion in 'iOS Code Snippets' started by tufanv, Apr 13, 2015.

  1. tufanv

    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
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Code:
    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
     
    tufanv likes this.
  3. ilan

    ilan Expert Licensed User

    hi

    is it possible to capture a part of the screen and not the whole screen?
    maybe with rect?

    thanx
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    A simple solution is to capture the whole screen and use the new Bitmap.Crop method to get part of it.
     
  5. ilan

    ilan Expert Licensed User

    New bitmap crop method you mean in b4i v4.3?
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    Yes.
     
  7. ilan

    ilan Expert Licensed User

    I have issues to use v4.3. (Ispritekit)

    Is there a solution for v4.01?
     
    Last edited: Sep 28, 2017
  8. Erel

    Erel Administrator Staff Member Licensed User

Loading...