MCPcopy Create free account
hub / github.com/Snapchat/Valdi / snapshot

Method snapshot

valdi/src/java/com/snap/valdi/ViewRef.kt:280–322  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

278 }
279 }
280
281 @Keep
282 fun snapshot(callback: ValdiFunction) {
283 var bitmap: BitmapHandler? = null
284
285 fun handleError() {
286 ValdiMarshaller.use {
287 it.pushUndefined()
288 callback.perform(it)
289 }
290 bitmap?.release()
291 }
292
293 val view = get() ?: return handleError()
294
295 val width = view.width
296 val height = view.height
297
298 if (width < 1 || height < 1) {
299 return handleError()
300 }
301
302 try {
303 val renderCanvas = this.support.getRenderCanvas()
304
305 bitmap = this.support.bitmapPool.get(width, height) ?: return handleError()
306
307 drawViewInCanvas(renderCanvas, bitmap.getBitmap(), view, null, true)
308
309 val output = ByteArrayOutputStream()
310
311 this.support.getSnapshotExecutor().submit {
312 bitmap.getBitmap().compress(Bitmap.CompressFormat.PNG, 0, output)
313 ValdiMarshaller.use {
314 it.pushByteArray(output.toByteArray())
315 callback.perform(it)
316 }
317 bitmap?.release()
318 }
319 } catch (exc: Exception) {
320 this.support.logger.log(LogLevel.ERROR, exc, "Failed to take Snapshot of view with size ${width}x${height}")
321 handleError()
322 }
323 }
324
325 @Keep

Callers 2

snapshotViewMethod · 0.45
clipImageToCircleFunction · 0.45

Calls 12

getRenderCanvasMethod · 0.80
getSnapshotExecutorMethod · 0.80
useMethod · 0.80
getMethod · 0.65
performMethod · 0.65
logMethod · 0.65
getFunction · 0.50
handleErrorFunction · 0.50
getBitmapMethod · 0.45
submitMethod · 0.45
pushByteArrayMethod · 0.45
releaseMethod · 0.45

Tested by

no test coverage detected