开发者

In the onDraw() method, why does the supplied Canvas already have scale?

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.

The XML layout file consists of nothing more than a FrameLayout, which c开发者_如何学Goontains 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.

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.

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.

Thanks,

Trev


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜