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

In the current test project, I have a custom view, which I called SVGView, which simply draws some kind of vector graphics (outlines, etc.) on the canvas.

An XML layout file consists of nothing more than a FrameLayout that contains a single child SVGView. Attributes android:layout_widthand android:layout_heightfor SVGView this example are set as 300px(FrameLayout which contain more than enough space for placement). In SVGView, the onMeasure()call setMeasuredDimension()is specified by arguments 300, 300.

When a method onDraw()is called to draw graphics into a Canvas object, I find that Canvas does not have an identification matrix; rather, Canvas has a number of zooms that are already applied. What is the reason for this? I (erroneously) assumed that the Canvas will have a scale of 1, since the actual dimensions of the View, its Canvas, and its presentation on the screen all match.

I ask about this in connection with the problem that I described in detail in my previous question here: The bitmap of the drawing cache is a bit blurry or has an anti-alias, I find that when I draw a cache bitmap back to the canvas, it is slightly blurry compared to the original vector graphics, despite the fact that I draw a bitmap without scaling, and using Paint with anti-aliasing disabled, Now I absolutely I’m sure there must be some kind of scaling process that I don’t know for this to happen with the bitmap. To find that the Canvas argument to onDraw () has a scaling transformation already applied is probably a big key to solving this problem, but I can’t understand why it has such scaling when the Canvas sizes perfectly match the area of ​​the screen that it ultimately draws.

Thank,

Trev

+2
source share
1 answer

minSdkVersion targetSdkVersion ? API 4, , G1.

+4

All Articles