Reputation: 447
I am creating an application using ARCore to display some images on blank surface. I want to capture image of that surface where object is display. I have put a capture button on AR camera screen.
Is it possible to capture that view with objects in ARCore camera?
Upvotes: 6
Views: 3150
Reputation: 58043
The method below allows you acquire an image from the Sceneform's scene that corresponds to the current frame along with a background image from camera's current AR frame. To capture a content of viewport, use the following approach:
fun makingTheScreenShot(
leftTopRightBottom: Rect,
activity: Activity,
onLuck: (Bitmap) -> Unit
) {
val bitmap = Bitmap.createBitmap(
leftTopRightBottom.width(),
leftTopRightBottom.height(),
Bitmap.Config.ARGB_8888
// each pixel is stored on 4 bytes
)
PixelCopy.request(
activity.window,
leftTopRightBottom,
bitmap,
{ if (it == PixelCopy.SUCCESS) onLuck(bitmap) },
Handler(Looper.getMainLooper())
// main thread of the app
)
}
Then save it to disk (you can try this method):
makingTheScreenShot(
activity.getViewRect()
activity,
) {
// Use your function to save
// a captured image to disk
}
Upvotes: 2
Reputation: 161
If you simply need a screenshot of the ARCore view you can try using some Android functionality such as PixelCopy.request(view, bitmap, (copyResult)->{})
on the ArSceneView of the ARCore fragment.
Source: https://codelabs.developers.google.com/codelabs/sceneform-intro/index.html?index=..%2F..io2018#15
Upvotes: 3