Canvas: Density Pixels to draw pictures

0

Good afternoon! Home 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 depending on the smartphone screen, the marker gets huge! Home I would like to know if it is possible, and how, to use Density Pixels (dp) in the code described above. Home Thanks in advance for your cooperation! Home Greetings,

    
asked by anonymous 21.08.2015 / 19:57

1 answer

0

Here's how I solved it:

 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);
    
21.08.2015 / 20:22