private fun saveView(view: View, context: Context, num: Int) : File? {
val Path = Environment.getExternalStorageDirectory().absolutePath
val dirPath = "${Path}/allokal/signature"
var file : File? = null
val b = Bitmap.createBitmap(
view.width, view.height, Bitmap.Config.RGB_565
)
val writePermission = ActivityCompat.checkSelfPermission(
context,
Manifest.permission.WRITE_EXTERNAL_STORAGE
)
if (writePermission == PackageManager.PERMISSION_GRANTED) {
if (b != null) {
try {
val f = File("$dirPath/allokal")
f.mkdir()
val f2 = File("$dirPath/allokal/$num.png")
val c = Canvas(b)
view.draw(c)
val fos = FileOutputStream(f2)
b.compress(Bitmap.CompressFormat.PNG, 100, fos)
fos.close()
file = f2
} catch (e: Exception) {
Log.e("testSaveView", "Exception: $e")
}
}
return file
}else{
return file
}
}