Posts

Post not yet marked as solved
2 Replies
1.5k Views
On iOS, I'm trying to convert the contents of a view produced by snapshotView(afterScreenUpdates:) into a UIImage. At the point where I'm trying to do this, I no longer have the underlying objects that were rendered into the snapshot - I only have the snapshot view.Although this snapshot view displays correctly on the device screen at all times, I seem to be unable to convert it to an image to save to disk.For example, say I do something like: let ssView = someView.snapshotView(afterScreenUpdates:true)And then later, I want to convert ssView to a UIImage. I have tried all the usual patterns that work with other (non-snapshot) views such as: UIGraphicsBeginImageContext(ssView.frame.size) ssView.drawHierarchy(in: ssView.bounds, afterScreenUpdates: true) let image = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext()or let renderer = UIGraphicsImageRenderer(size: ssView.frame.size) let image = renderer.image { context in return ssView.layer.render(in: context.cgContext) }And many other variations... I've also tried to render the hierarchy from superviews of the snapshot view but no matter what I try, it doesn't work. Attempting to capture the snapshot view directly produces a blank image and if the parent view is captured, the portion of the screen where the snapshot view resides is blank.Does anyone have any idea how to make this work?Thanks,David
Posted
by jodpurr.
Last updated
.
Post marked as solved
1 Replies
1.3k Views
I have built and run the example ARKit with Metal demo in XCode on iOS 11 beta 3 by choosing Augmented Reality and then Content Technology = Metal. It appears to run fine on my iPhone 7plus. Now I'd like to make one small change to it. The sample app is set to Device Orientation = LandscapeRight under Deployment Info. What I would like to do is switch it to run correctly in Portrait orientation but that doesn't seem to be a simple thing.There are two references to landscapeRight orientation in the code within Renderer.swift as follows:In updateSharedUniforms func updateSharedUniforms(frame: ARFrame) { / let uniforms = sharedUniformBufferAddress.assumingMemoryBound(to: SharedUniforms.self) uniforms.pointee.viewMatrix = simd_inverse(frame.camera.transform) uniforms.pointee.projectionMatrix = frame.camera.projectionMatrix(withViewportSize: viewportSize, orientation: .landscapeRight, zNear: 0.001, zFar: 1000) and in updateImagePlane func updateImagePlane(frame: ARFrame) { / let displayToCameraTransform = frame.displayTransform(withViewportSize: viewportSize, orientation: .landscapeRight).inverted()Changing these two enums from .landscapeRight to .portrait results in the app displaying the correct camera image in portrait mode but the anchor objects (as drawn by Metal) then don't stick to the right point in 3d space like they do in landscapeRight. Instead they start drifting off camera.There must be some part of the code that is still assuming the viewport is 736x414 instead of 414x736 but it is not at all obvious where that is. Hoping somebody knows something or at least has an idea where the issue might be. Thanks!
Posted
by jodpurr.
Last updated
.