Drawing a bitmap on canvas has become scaled

I created my own view with two bitmaps. When I use a bitmap outside my view, the ImageView is fine in the ImageView. I need to call setDensity(240)(hdpi device), but that's fine. However, in the user view, when I draw the same bitmap on the canvas, in the overridden method, onDraw(Canvas)it scales again, just like I don't call setDensity(240). After debugging, I ensured that the density of the canvas and bitmap was 240, after the call.

the code:

@Override
protected void onDraw(Canvas canvas) {    
    _ingredient.setDensity(240);
    canvas.setDensity(240);
    canvas.drawBitmap(_ingredient, new Matrix(), new Paint());
    Matrix refMatrix = new Matrix();
    refMatrix.postTranslate(0, _ingredient.getHeight()-35);
    Paint paint = new Paint();
    paint.setAlpha(60);
}

Working ImageView, out of my view.

Bitmap tertr = _cocktail.getCocktailBitmapImage();
tertr.setDensity(240);
ImageView in = new ImageView(this);
in.setScaleType(ScaleType.CENTER);
in.setImageBitmap(tertr);
RelativeLayout relativeLayout = RelativeLayout)findViewById(R.id.cocktail_date_image_layout);
LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
relativeLayout.addView(in, params);

, , , setDensity. 72dpi. , . , Canvas? , , - DROID2.

+3
2

. , , . <supports-screens android:anyDensity="false"/> true. True - , , , , . setDensity() .

+3

, , "" . , , . 160, , , . , .

, .

+1

Source: https://habr.com/ru/post/1792471/


All Articles