Search code examples
androidcanvasbitmapdrawmutable

Draw on Bitmap in dependency to screen size


I am working with two other people on a Android project (2.2) for my studies.

We want to show maps of some university buildings so you canf find rooms easier. We use a custom ImageView (TouchImageView).

I make the bitmap mutable with

plant = plant.copy(Bitmap.Config.ARGB_8888, true);

so I can lay the Canvas above it. Then I draw a red Circle on it with

Paint paint = new Paint(); paint.setColor(Color.RED); Canvas canvas = new Canvas(plant); canvas.drawCircle(xFromSearch, yFromSearch, 15, paint);

xFromSearch and yFromSearch are global variables which are already initialised with given values.

It works fine with my Google G1 but with other display sizes (e.g. the AVD or Samsung Galaxy SII) the circle is painted at the wrong place...

May it work when I do something with

Display display = getWindowManager().getDefaultDisplay(); screenWidth = display.getWidth(); screenHeight = display.getHeight();

??

I hope I gave you all the information you need and someone can help... Thank you very much!!!


Solution

  • try this

    int scale = getApplicationContext().getResources().getDisplayMetrics().density;
    canvas.drawCircle(xFromSearch*scale , yFromSearch*scale , 15*scale , paint);