D
Deleted member 103
Guest
Hi,
the prehistory of this thread comes from this b4a-thread.
This B4a code works very well for B4a:
For B4i I had previously used this code, unfortunately, the performance was not so good.
Then I thought that with the equivalent B4a code performance would have been better, but unfortunately not so.
Is there anything better for B4i?
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
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?