安卓:允许的最大宽度放;位图的高度位图、宽度、高度、最大

2023-09-12 09:24:13 作者:丧命之徒

林创建一个应用程序,需要去code大图像,位图显示在ImageView的。

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

如果我只是试着去$ C C $他们直接到一个位图,我收到以下错误 位图太大而不能上传到一个纹理(1944x2592,上限= 2048×2048)

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)"

因此​​,为了能够显示与使用过高的分辨率IM图像:

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);             
}

这工作,但我真的不希望到c 2048最大值硬$ C $,因为我已经在if语句,但我不能找出如何得到位图的最大允许的大小设备

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

任何想法?

推荐答案

这个限制应该从底层OpenGL实现到来。如果你已经使用OpenGL在你的应用程序,你可以使用这样的事情,以获得最大尺寸:

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)

这表明我我的两个Galaxy Nexus的和Galaxy S2有一个最大的2048×2048。

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

不幸的是,如果你不是已经在使用它,只有这样才能得到一个OpenGL上下文来调用这个从是创建一个(包括surfaceview等),这是一个很大的开销只是为了查询一个最大尺寸

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.