在的OnDraw()方法时,为什么提供的帆布已经有规模有多大? [英] In the onDraw() method, why does the supplied Canvas already have scale?

查看:86
本文介绍了在的OnDraw()方法时,为什么提供的帆布已经有规模有多大?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在当前的测试项目中,我有一个自定义视图,我有一个名为SVGView,简单地描绘了一些矢量图形(路径等),到画布上。

In a current test project I have a custom View, that I have named SVGView, that simply paints some vector graphics (Paths, etc.) to the Canvas.

在XML布局文件包含比的FrameLayout,其中包含一个孩子SVGView罢了。该的android:layout_width 安卓layout_height 属性在当前的例子中,SVGView都设置为为300px (其中含的FrameLayout有足够的空间来容纳)。在SVGView的 onMeasure(),调用 setMeasuredDimension()给出的参数300,300

The XML layout file consists of nothing more than a FrameLayout, which contains a single child SVGView. The android:layout_width and android:layout_height attributes for the SVGView in the current example are both set to 300px (which the containing FrameLayout has more than enough room to accommodate). In the SVGView's onMeasure(), the call to setMeasuredDimension() is given the arguments 300, 300.

的OnDraw()方法被调用来绘制图形的Canvas对象,我发现画布没有一个单位矩阵;相反,画布有规模的改造已经应用了一定量。什么是这种情况的原因是什么?我(错误地)认为画布将有1缩放,因为视图,它的画布,并在屏幕上其重新presentation所有比赛的实际尺寸。

When the onDraw() method is called to draw the graphics to the Canvas object, I find that the Canvas doesn't have an identity matrix; rather, the Canvas has some amount of scale transformation already applied. What's the reason for this? I (wrongly) assumed that the Canvas would have a scaling of 1, because the actual dimensions of the View, its Canvas, and its representation on the screen all match.

我问这相对于我进行了详细的我这里前面提到的问题:<一href="http://stackoverflow.com/questions/6278509/canvas-drawing-cache-bitmap-is-slightly-blurred-or-has-anti-alias">Canvas绘图缓存位图是有点模糊或者具有抗混叠。我发现,当我画缓存位图回到画布,它比原来的矢量图形的轻微模糊,尽管我画的位图后面不使用的重新调整,并用涂料具有抗混叠关闭。现在我只是绝对相信那里必须有部分的缩放的过程,我不知道导致这种情况发生的位图。要发现画布参数的OnDraw()已经包括了一些缩放变换可能是一个很大的线索解决这个问题 - 但我不明白为什么它有这样的调整,当肯定是Canvas的尺寸完全匹配的区域屏幕它的最终绘画到。

I'm asking this in relation to the problem I have described in detail in my earlier question here: Canvas drawing cache bitmap is slightly blurred or has anti-alias. I'm finding that when I draw the cache bitmap back to the Canvas, it's slightly blurred compared to the original vector graphics, despite the fact that I'm drawing the bitmap back using no rescaling and using a Paint with anti-alias turned off. I'm now just absolutely convinced there there has to be some scaling process that I'm unaware of causing this to happen to the bitmap. To discover that the Canvas argument to onDraw() has some scaling transformation already applied is possibly a big clue to solving this problem -- but I can't understand why it has such scaling, when surely the Canvas' dimensions perfectly match the area of the screen it's ultimately painting to.

谢谢

崔佛

推荐答案

你宣布的minSdkVersion或targetSdkVersion在你的清单?如果你的目标的API级别低于4您的应用程序将在缩放的兼容模式下运行,就好像它是一个针对G1的屏幕。

Have you declared a minSdkVersion or targetSdkVersion in your manifest? If you are targeting an API level lower than 4 your app will run in scaled compatibility mode as if it were targeting a G1 screen.

这篇关于在的OnDraw()方法时,为什么提供的帆布已经有规模有多大?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆