我希望将Google地图的屏幕快照保存在列表视图中,但是当我执行该操作时,它只显示地图的黑屏,但是我得到了屏幕
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
var t = inflater.inflate(R.layout.fragment_map, container, false)
var download = t.findViewById(R.id.download) as FloatingActionButton
var imageView=t.findViewById(R.id.imageView) as ImageView
mapFragment = childFragmentManager.findFragmentById(R.id.map) as SupportMapFragment?
mapFragment!!.getMapAsync(this)
download.setOnClickListener(){
var bitmap: Bitmap? = getBitmapRootView(it)
imageView.setImageBitmap(bitmap)
createImage(bitmap!!)
}
return t
}
}
private fun getBitmapRootView(v: View): Bitmap {
val rootView = v.rootView
rootView.isDrawingCacheEnabled = true
return rootView.drawingCache
}
private fun createImage(bmp: Bitmap) {
val bytes = ByteArrayOutputStream()
bmp.compress(Bitmap.CompressFormat.JPEG, 40, bytes)
val file = File(Environment.getExternalStorageDirectory().toString().plus("/captured_screen_shot.jpg"))
try {
file.createNewFile()
val outputStream = FileOutputStream(file)
outputStream.write(bytes.toByteArray())
outputStream.close()
} catch (e: Exception) {
e.printStackTrace()
}
}
}
我希望获得我的googlemap的屏幕截图,但实际上只是黑屏
文件:///home/khouloud/T%C3%A9l%C3%A9chargements/Screenshot_2019-04-23-09-29-37.png