1
votes

I'm writing an app which uses a large-ish (1024x1024) bitmap. I've noticed that the performance drops significantly when it's being rendered, so I'd like to calculate the exact size of its ImageView in pixels such that the bitmap can be scaled once, instead of being scaled internally on every single frame (which is what I assume is currently happening - the profiler tells me that the internal draw() function alone takes up to ~30ms when the image is on-screen)

However, I'm not sure how to ensure that my image won't be scaled internally, since the display manager's resolution and density are COMPLETELY off.

getWindowManager().getDefaultDisplay().getRealMetrics() returns

density=3.00000, densityDpi=480, heightPixels=1920, scaledDensity=3.00000, widthPixels=1080, xdpi=442.451, ydpi=443.345

getWindowManager().getDefaultDisplay().getMetrics() returns

density=1.00000, densityDpi=160, heightPixels=526, scaledDensity=1.00000, widthPixels=320, xdpi=147.484, ydpi=147.782

While getResources().getDisplayMetrics() returns

density=1.00000, densityDpi=160, heightPixels=175, scaledDensity=1.00000, widthPixels=107, xdpi=147.484, ydpi=147.782

The issue is that all layout calculations (including px units) are based off the latter two, not the former. This is being run on my Moto G5.

I'm assuming there's something I'm missing in either my AndroidManifest.xml or activity_main.xml?

1

1 Answers

0
votes

Make sure you set an SDK version in AndroidManifest.xml directly inside the manifest section, eg.

<uses-sdk
  android:minSdkVersion="15"
  android:targetSdkVersion="28"
/>

I figured it out when trying to get hardware acceleration working and I noticed that it was tied to the window manager.

From the docs:

Hardware acceleration is enabled by default if your Target API level is >=14, but can also be explicitly enabled.