如何優雅的完成長截圖?

效果圖.gif

安利一個截長圖的工具ScreenShotToolsgit

ScreenShotTools

ScreenShotTools是一個Android長截圖工具。目的是輕鬆搞定常見的View截圖功能。 目前功能有:github

1. ScrollView的截圖
2. RecyclerView的截圖
3. WebView的截圖
4. View的截圖
5. 各截圖提供拼接頭部和尾部功能
複製代碼

使用方法:

gradle配置
  1. 在最外層的build.gradle中添加maven地址(已傳入JCenter,本步驟能夠忽略)
allprojects {
    repositories {
       ..
        maven { url 'https://dl.bintray.com/missmydearbear/maven' }
    }
}

複製代碼
  1. app目錄下的build.gradle中添加
implementation "com.bear:ScreenShotTools:1.0"
複製代碼
Api
//1.只截傳入的View
 fun takeCapture(context: Context, view: View, callBack: IScreenShotCallBack?) 
//2.拼接頭部圖片
 fun takeCapture(context: Context, view: View, topBitmap: Bitmap?, callBack: IScreenShotCallBack?) 
//3.拼接頭部和底部圖片
 fun takeCapture(
        context: Context,
        view: View,
        topBitmap: Bitmap?,
        bottomBitmap: Bitmap?,
        callBack: IScreenShotCallBack?
    ) 
//4. 拼接頭部和底部圖片,且傳入圖片的寬度
 fun takeCapture(
        context: Context,
        view: View,
        topBitmap: Bitmap?,
        bottomBitmap: Bitmap?,
        width: Int,
        callBack: IScreenShotCallBack?
    ) 

複製代碼

demo

以RecyclerView爲例bash

override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_recycler_view)
        tv.setOnClickListener {
            ScreenShotTools.instance.takeCapture(this, recycler_view, object : IScreenShotCallBack {
                override fun onResult(screenBitmap: ScreenBitmap?) {
                    //todo do your things
                }

            })
        }
        loadData()
    }
複製代碼

gitHub:github.com/MissMyDearB…app

相關文章
相關標籤/搜索