How to get drawn Image width/height on the screen with openGL ES on Android?

I need to know how to get drawn image length and width.

I have this code so far where I draw Radar in left top corner with hard-coded coordinates:

int _SRC = R.drawable._item;

...

float vertices[] = {
0f,  0f,  0.0f,
0f,  2.0f,0.0f,
2.0f,0f,  0.0f,
2.0f,2.0f,0.0f
};
...

...

this.x = x;
this.y = y;
}

...

private void updateScreenData(float screenWidth, float screenHeight){
// takes screen Height and Width
this.mScreenWidth = (screenWidth > 0) ? screenWidth : 1f;
this.mScreenHeight = screenHeight;
wRatio = 10f/mScreenWidth;
hRatio = mScreenHeight/10f;
}

@Override

InputStream is;

is = mContext.getResources().openRawResource(_SRC);

Bitmap bitmap = BitmapFactory.decodeStream(is);

try {
is.close();
is = null;
} catch (IOException e) {
}

gl.glGenTextures(TEXTURE_COUNT, textures, 0);

gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);

bitmap.recycle();

}

gl.glPushMatrix();
try {
float transx =  (wRatio * (x));
float transy =  (mScreenHeight*wRatio) - (wRatio * (y)) - 1/hRatio;
// Log.e(LOG_TAG, "transx: " + transx + "; transy: " + transy + "; sprite.x: "+  sprite.x + "; sprite.y: " + sprite.y);

gl.glTranslatef(transx, transy, 0.0f);

//###########  draw ##############

gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);

gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, floatBufferArray[mFrame]);

//update();

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, vertices.length / 3);
gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

//###############################

} catch (NullPointerException e) {
}
gl.glPopMatrix();
}


I used addRadarToView(0,240); to set x=0 and y= 240;

So as I see x represents left border of vertices. When 240 is y that represents bottom border. Strange.

[EDIT]

In canvas i used something like:

 int srcX = currentFrame * width;

Rect  src = new Rect(srcX, 0, srcX+width, height);
Rect  dst = new Rect(x, y, x+width, y+height);
canvas.drawBitmap(bitmap, src, dst, null);


Where width and height are:

bitmap.getWidth();
bitmap.getHeight();


Please, help me to sort it out.

Thanks,

• Did you call updateScreenData() with the correct resolution? – Mario Jul 25 '13 at 9:54
• yep, from Parent class, its working code, just want to replace hard-coded part: addRadarToView(0,240); – Maxim Shoustin Jul 25 '13 at 10:53
• Not really sure what you're asking then? Do you want to calculate the actual coordinates where the radar is drawn to? – Mario Jul 25 '13 at 10:54
• when I draw vertice on the screen, I tell where to draw it (x,y). But position should be based on Bitmap size. otherwise if image is big, it can be out of the screen – Maxim Shoustin Jul 25 '13 at 10:57
• Still not really sure what you're looking for. Are you unhappy with the origin of the radar screen (i.e. the point you pass to draw it)? – Mario Jul 25 '13 at 11:06