开发者

Android OpenGL: Bitmap.getHeight() > actual height

开发者 https://www.devze.com 2023-04-05 02:50 出处:网络
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.background); My background.png has a size of 512x512px
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.background);

My background.png has a size of 512x512px

I use BitmapFactory to load the Bitmap of the background resource file.

The strang thing:

Lo开发者_运维知识库g.d("bitmap height", bmp.getHeight() + "px");

always returns 768px.

How is this possible?

My openGL is setup like this:

width = 480;
height = 800;
gl.glViewport(0, 0, width, height);
gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadIdentity();
gl.glOrthof(0.0f, width, 0.0f, height, -1.0f, 1.0f);

gl.glShadeModel(GL10.GL_FLAT);
gl.glEnable(GL10.GL_BLEND);
gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
gl.glColor4x(0x10000, 0x10000, 0x10000, 0x10000);
gl.glEnable(GL10.GL_TEXTURE_2D);


gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_FASTEST);
gl.glClearColor(0.5f, 0.5f, 0.5f, 1);
gl.glDisable(GL10.GL_DEPTH_TEST);
gl.glDisable(GL10.GL_DITHER);
gl.glDisable(GL10.GL_LIGHTING);
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);


BitmapFactory will scale the bitmap when the bitmap's DPI doesn't match the screen's DPI. The solution is to set the inScaled option to false:

BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inScaled = false;
Bitmap bmp = BitmapFactory.decodeResource(getResources(),
    R.drawable.background, opts);


768 / 512 = 1.5 This is the factor used for your screen resolution.

0

精彩评论

暂无评论...
验证码 换一张
取 消