Wednesday, 15 February 2012

Plotting dots on android canvas -



Plotting dots on android canvas -

i developing android game application provide tracing letter functionality.this first time working android graphics.here using canvas app.i want display dotted letter on canvas allows user trace letters on screen.for created images of dotted letters , set images in background.

now want plot points on these dotted letter image @ particular (x,y) coordinate. problem android canvas depends on different screen size. hence i'll have scale these point(x,y) coordinates according screen size.i referred this link couldn't clear idea.

please help me solve problem. thanks.

first find height , width of screen .

int width = game.getwindowmanager().getdefaultdisplay().getwidth(); int height = game.getwindowmanager().getdefaultdisplay().getheight();

scale background cover screen

bitmap background_scaled=bitmap.createscaledbitmap(background, width, height, true);

convert (x,y) --> (x_scaled,y_scaled)

int x_scaled=x*((float)width/(float)background.getwidth()); int y_scaled=y*((float)width/(float)background_getheight());

draw point

canvas.drawpoint(x_scaled,y_scaled,new paint());

android android-canvas android-view

No comments:

Post a Comment