Created
September 10, 2020 06:53
-
-
Save floriangbh/dc452ee09c2ca4cc99d0bdd8811aaaf2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainActivity : AppCompatActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
} | |
override fun onResume() { | |
super.onResume() | |
val customView = CustomView(applicationContext) | |
customView.measure(View.MeasureSpec.makeMeasureSpec(1280, View.MeasureSpec.EXACTLY), | |
View.MeasureSpec.makeMeasureSpec(720, View.MeasureSpec.EXACTLY)) | |
customView.layout(0, 0, customView.measuredWidth, customView.measuredHeight) | |
loadBitmapFromView(customView).let { bitmap -> | |
this.imageView.setImageBitmap(bitmap) | |
} | |
} | |
fun loadBitmapFromView(view: View): Bitmap? { | |
val bitmap: Bitmap = Bitmap.createBitmap(view.width, view.height, Bitmap.Config.ARGB_8888) | |
val canvas = Canvas(bitmap) | |
view.layout(view.left, view.top, view.right, view.bottom) | |
view.draw(canvas) | |
return bitmap | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment