All Projects → bolteu → Screenshotty

bolteu / Screenshotty

Licence: mit
A library for programatically capturing screenshots on Android

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to Screenshotty

Screen capture lite
cross platform screen/window capturing library
Stars: ✭ 340 (+141.13%)
Mutual labels:  screenshot, screen-capture, screenshots
Falcon
Take Android screenshots with Falcons bright eye!
Stars: ✭ 362 (+156.74%)
Mutual labels:  screenshot, screen-capture, screenshots
autoscreen
Automated screen capture utility
Stars: ✭ 76 (-46.1%)
Mutual labels:  screenshot, screenshots, screen-capture
Snapshots For Windows
Application for make and upload screenshots / Приложение для создания и загрузки скриншотов
Stars: ✭ 6 (-95.74%)
Mutual labels:  screenshot, screen-capture, screenshots
Swift Screencapture
A Swift framework to easily capture the screen on OS X.
Stars: ✭ 105 (-25.53%)
Mutual labels:  screenshot, screen-capture, screenshots
Chart To Aws
Microservice to generate screenshot from a webpage and upload it to a AWS S3 Bucket.
Stars: ✭ 43 (-69.5%)
Mutual labels:  screenshot, screen-capture, screenshots
screenshotgun
Open cross-platform screenshoter with cloud support and server part
Stars: ✭ 23 (-83.69%)
Mutual labels:  screenshot, screenshots
urlbox-screenshots-node
Capture website thumbnails using the urlbox.io screenshot as a service API in node
Stars: ✭ 14 (-90.07%)
Mutual labels:  screenshot, screenshots
freeshooter
This is old-school tool for taking screenshots without bloatware features, simple as life, light as air.
Stars: ✭ 102 (-27.66%)
Mutual labels:  screenshot, screenshots
Live-Desktop-Capture
A Live Desktop Capture using Go and WebSockets
Stars: ✭ 42 (-70.21%)
Mutual labels:  screenshot, screen-capture
Menyoki
Screen{shot,cast} and perform ImageOps on the command line 🌱 🏞️
Stars: ✭ 255 (+80.85%)
Mutual labels:  screenshot, screen-capture
Screenshot
Go library to capture desktop to image
Stars: ✭ 545 (+286.52%)
Mutual labels:  screenshot, screen-capture
accelerator-core-ios
Syntax sugar of OpenTok iOS SDK with Audio/Video communication including screen sharing
Stars: ✭ 30 (-78.72%)
Mutual labels:  screenshots, screen-capture
dot-screencap
A screencapturing library
Stars: ✭ 31 (-78.01%)
Mutual labels:  screenshot, screen-capture
Svg Screenshot
リンクもまるごとキャプチャしてSVGで出力するChromeスクリーンショット拡張機能
Stars: ✭ 31 (-78.01%)
Mutual labels:  screenshot, screen-capture
Upscreen
Capture your screen, upload to your own server.
Stars: ✭ 17 (-87.94%)
Mutual labels:  screenshot, screen-capture
Gowitness
🔍 gowitness - a golang, web screenshot utility using Chrome Headless
Stars: ✭ 996 (+606.38%)
Mutual labels:  screenshot, screenshots
go-scrap
Go library to capture screen pixels for screenshots or screen recording
Stars: ✭ 68 (-51.77%)
Mutual labels:  screenshot, screen-capture
AutoScreenshot
Automatic screenshot maker for Windows
Stars: ✭ 49 (-65.25%)
Mutual labels:  screenshot, screenshots
Imgursniper
📷 A quick and easy Image, Screenshot and Screen recording sharing tool
Stars: ✭ 69 (-51.06%)
Mutual labels:  screenshot, screen-capture

Screenshotty

The library combines MediaProjection, PixelCopy and Canvas drawing and provides an easy-to-use API, abstracted from the Android framework and the complexities of the underlying mechanisms, to capture precisely what a user sees on their screen.

The sample app shows how to use the library.

Gradle

Add this to your dependencies block.

implementation 'eu.bolt:screenshotty:1.0.3'

To use a reactive wrapper also add:

implementation 'eu.bolt:screenshotty-rx:1.0.3'

Wiki

General

If we want to capture a screenshot inside the app, the simplest approach is to draw the root view on a Bitmap, but this approach won't work correctly if there are open dialogs, or view hierarchy contains maps or other SurfaceViews. Screenshotty uses PixelCopy and MediaProjection to provide the correct image in all these cases.

First the library tries to make a PixelCopy with dialogs, retrieved via reflection, rendered on top.

If this approach fails, user will see a record screen permission dialog. Screenshotty minimizes the number of times the dialog is shown: permission has to be granted only once per process lifetime. If "Don't show again" option (removed in Android 10) is checked, the system will remember user's choice for all the future invocations. If the permission is granted, a MediaProjection API is used to take a single frame and provide it to result listeners.

In case MediaProjection fails, fallback strategies are invoked one-by-one until the first one succeeds to provide a Bitmap.

Usage

  1. Create a ScreenshotManager:
screenshotManager = ScreenshotManagerBuilder(this)
   .withPermissionRequestCode(REQUEST_SCREENSHOT_PERMISSION) //optional, 888 is the default
   .build()
  1. Make sure the object receives activity results:
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
   super.onActivityResult(requestCode, resultCode, data)
   screenshotManager.onActivityResult(requestCode, resultCode, data)
}
  1. Request a screenshot and observe the result:
val screenshotResult = screenshotManager.makeScreenshot()
val subscription = screenshotResult.observe(
   onSuccess = { processScreenshot(it) },
   onError = { onMakeScreenshotFailed(it) }
)
  1. If you're no longer interested in the result (as when your Activity is destroyed), you can unsubscribe your observers using the object you got from observe().
override fun onDestroy() {
   super.onDestroy()
   subscription.dispose()
}

Working with result

When you receive a Screenshot you can either get a Bitmap object from it:

fun show(screenshot: Screenshot) {
   val bitmap = when (screenshot) {
      is ScreenshotBitmap -> screenshot.bitmap
   }
   screenshotPreview.setImageBitmap(bitmap)
}

Or use ScreenshotFileSaver provided by the library to write the image to a file:

fun writeToFile(screenshot: Screenshot): File {
   val fileSaver = ScreenshotFileSaver.create(Bitmap.CompressFormat.PNG)
   val targetFile = File(context.filesDir, "screenshot")
   fileSaver.saveToFile(targetFile, screenshot)
   return targetFile
}

Reactive wrapper

If you're using screenshotty-rx, you can transform your ScreenshotManager object into RxScreenshotManager:

val rxScreenshotManager = screenshotManager.asRxScreenshotManager() //or RxScreenshotWrapper.wrap(screenshotManager)

Usage is exactly the same, but makeScreenshot() returns Single<Screenshot> instead of ScreenshotResult, so you can use all the expressive power of reactive composition to process the result:

subscription = rxScreenshotManager.makeScreenshot()
   .observeOn(Schedulers.io())
   .map(::writeToFile)
   .doOnSuccess(::sendScreenshotFile)
   .observeOn(AndroidSchedulers.mainThread())
   .subscribe(
      onSuccess = ::onScreenshotSent,
      onError = ::handleError
   )

Fallback strategies

When constructing a ScreenshotManager you can add any number of objects that implement FallbackStrategy interface. If PixelCopy or MediaProjection fails for some reason, fallback strategies will be invoked one by one in the order they were added, until the first one succeeds to provide a Bitmap.

If no strategies were added or all of them failed, the default one (that simply calls draw on the root view and tries to render dialogs retrieved via reflection on top) will be invoked.

License

MIT License

Copyright (c) 2020 Bolt Technologies OÜ

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].