Canvas: Density Pixels to draw images

Asked

Viewed 38 times

0

Good afternoon !
I’m creating a custom Marker for the map:

        final Bitmap markerIcon = Bitmap.createBitmap(275, 275, Bitmap.Config.ARGB_8888);
        final Paint paint = new Paint();
        final Canvas canvas = new Canvas(markerIcon);

I’m using fixed sizes for the images, so I depend on the smartphone screen, the Marker gets giant!
I wonder if it is possible, and how, to use Density Pixels (dp) in the code described above.
Thanks for your cooperation!
Greetings,

1 answer

0


It goes on as I resolved:

 DisplayMetrics metrics = new DisplayMetrics();
                 getWindowManager().getDefaultDisplay().getMetrics(metrics);
                 Integer _SizePin = Math.round(  Float.valueOf(100)* metrics.density );
                 Integer _SizePhoto = Math.round(  Float.valueOf(50)* metrics.density );

                final Bitmap markerIcon = Bitmap.createBitmap(_SizePin, _SizePin, Bitmap.Config.ARGB_8888);
                final Paint paint = new Paint();
                final Canvas canvas = new Canvas(markerIcon);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.