iOS Question Share iOS-App-View

D

Deleted member 103

Guest
Hi,

the prehistory of this thread comes from this b4a-thread.

This B4a code works very well for B4a:
B4X:
Private Sub TakeScreenshot As Bitmap
Dim x As B4XView = Activity
Dim bmp As Bitmap = x.Snapshot.Resize(600, 600, True)
return bmp
End Sub

For B4i I had previously used this code, unfortunately, the performance was not so good.
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

Then I thought that with the equivalent B4a code performance would have been better, but unfortunately not so.
B4X:
Private Sub TakeScreenshot As Bitmap
    Dim x As B4XView = pMain.RootPanel
    Return x.Snapshot.Resize(600, 600, True)
End Sub

Is there anything better for B4i?
 
D

Deleted member 103

Guest
After my test I have these results:
B4X:
Private Sub mirrorTimer_Tick
    If smanager.IsClientConnected Then
        Dim n As Long = DateTime.Now
        Dim jpeg() As Byte = ConvertBitmapToByte(TakeScreenshot)
        smanager.NewBitmap(jpeg)
        Log(DateTime.Now - n)
    End If
End Sub
Average time = 200-300 milliseconds

B4X:
Private Sub mirrorTimer_Tick
    If smanager.IsClientConnected Then
        Dim n As Long = DateTime.Now
        
        Dim no As NativeObject = Me
        Dim bmp As Bitmap = no.RunMethod("TakeScreenshot", Null)
    
        'Log("mirrorTimer_Tick")
        Dim jpeg() As Byte = ConvertBitmapToByte(bmp)
        smanager.NewBitmap(jpeg)
        
        Log(DateTime.Now - n)
        
    End If
End Sub
Average time = 60-90 milliseconds

When transferring the images, I have a latency of about 2-5 seconds.
 
Upvote 0
D

Deleted member 103

Guest
We are talking only about the time it takes to create the snapshot
I don't really understand your code.
You're right! To understand that, you have to be able to read my thoughts. :rolleyes:

In any case, the 2 codes (see above) need the same time when making a bitmap.resize.

When transferring the images, I have a latency of about 2-5 seconds.
Although belonging to the same app, but it's a different topic.
 
Upvote 0
Top