0
  bitmap?.let {
                            cropimg = Bitmap.createBitmap(
                                it,
                                0,
                                56+28,//each mobile has different height of actionbar and status bar
                                it.width,
                                it.height -(56+28)
                            )
                        }

I am taking Screenshot of mobile screen and I am getting bitmap as a result

I want to crop the status bar or navigation bar from that bitmap How to do that? I try above solution but it is not accurate.

  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Nov 28 '21 at 15:52
  • I am taking screenshot of my screen but I don't want the status bar (sometime navigation bar) in that So how can I achieve that ? (I am getting bitmap as a result of ss) – Mohammad Taqi Velani Nov 30 '21 at 07:23

1 Answers1

0

Step 1: Get the dynamic height of the status bar

fun getStatusBarHeight(context: Context): Int {
    val resources: Resources = context.resources
    val resourceId: Int = resources.getIdentifier("status_bar_height", "dimen", "android")
    return if (resourceId > 0) resources.getDimensionPixelSize(resourceId) else 0
}

Step 2: Point out the starting point of your new bitmap like this

          val statusbarHeight = getStatusBarHeight(this)

           bitmap?.let {
                            cropimg = Bitmap.createBitmap(
                                it,
                                0,
                                0 + statusbarHeight,
                                it.width,
                                it.height
                            )
                        }

Happy Conding! :)

Rezwan
  • 61
  • 2