Question: Im creating an app that needs to decode large images to bitmaps to be displayed in a ImageView.

If i just try to decode them straight to a bitmap i get the following error
" Bitmap too large to be uploaded into a texture (1944x2592, max=2048x2048)"

So to be able to show images with too high resolution im using: 

```
Bitmap bitmap = BitmapFactory.decodeFile(path);

if(bitmap.getHeight()>=2048||bitmap.getWidth()>=2048){
    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    int width = metrics.widthPixels;
    int height = metrics.heightPixels;
    bitmap =Bitmap.createScaledBitmap(bitmap, width, height, true);             
}

```

This works but I don't really want to hardcode the maximum value of 2048 as I have in the if-statement now, but I cant find out how to get a the max allowed size of the bitmap for a device

Any ideas?

Answer: 
This limit should be coming from the underlying OpenGL implementation. If you're already using OpenGL in your app, you can use something like this to get the maximum size:

```
int[] maxSize = new int[1];
gl.glGetIntegerv(GL10.GL_MAX_TEXTURE_SIZE, maxSize, 0);
// maxSize[0] now contains max size(in both dimensions)

```

This shows that my both my Galaxy Nexus and Galaxy S2 have a maximum of 2048x2048.

Unfortunately, if you're not already using it, the only way to get an OpenGL context to call this from is to create one(including the surfaceview, etc), which is a lot of overhead just to query a maximum size.
If you're on API level 14+ (ICS) you can use the `getMaximumBitmapWidth` and `getMaximumBitmapHeight` functions on the `Canvas` class. This would work on both hardware accelerated and software layers.

I believe the Android hardware must at least support 2048x2048, so that would be a safe lowest value. On software layers, the max size is 32766x32766.