问题描述
我创建了一个自定义视图,有两个位图。当我使用位图的我的看法之外,在ImageView的,图像确定。我必须调用 setDensity(240)
(华电国际设备),但它的确定。然而,在自定义视图,当我得出同样的位图在画布上,在的OnDraw(画布)
覆盖方法,它再次缩小,以同样的方式,当我不牛逼呼叫 setDensity(240)
。经由调试,我确保了画布和位图的密度为240时,呼叫后。
I created a custom View, with two Bitmaps. When I use the Bitmap outside of my View, in an ImageView, the image is OK. I have to call setDensity(240)
(hdpi device), but it's ok.However, in the custom View, when I draw the same Bitmap on a canvas, in the onDraw(Canvas)
overridden method, it's scaled again, the same way when I don't call setDensity(240)
.Via debugging, I ensured that the density of the canvas and bitmap is 240, after the call.
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);
}
工作ImageView的,我的观之外。
The working ImageView, outside 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的创建图像。这些图像被赋予的,我不能改变它们。我失去了一件事,或者这是画布是如何工作的?用于测试的装置是DROID2
The first one is showing the image scaled up, just like the second one, without the setDensity call. The images were created at 72dpi. These images are given, I cannot change them. Am I missing one thing, or this is how Canvas works? The device used for testing is a DROID2.
推荐答案
我解决了这个问题。造成麻烦的code段是在manifest文件。我们改变<支持屏安卓anyDensity =FALSE/>
为true。真正的是默认的,但不幸的是我改变了这一切,而我是在尝试不同的方法。随着新的价值,而 setDensity()
的方法,它的工作。
I solved the problem. The code snippet that caused the trouble was in the manifest file.We changed <supports-screens android:anyDensity="false"/>
to true. True is the default, but unfortunately I changed that while I was trying different approaches. With the new value, and the setDensity()
methods, it's working.
这篇关于绘制在画布位图得到了缩放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!