Until 4.2 the hardware accelerated rendering pipeline would render circles
as a texture using the radius you specify in the drawCircle() call. It
would then scale the texture based on the Canvas transform. In this case
you are stretching a picture of a circule that's 1px large, which is why
you are getting a rectangle. Instead of using Canvas.scale(), set the
radius you want directly. Note that we lifted this limitation in 4.2.


On Fri, Jun 21, 2013 at 9:32 AM, Leith Bade <[email protected]>wrote:

> I have been banging my head for a while trying to figure out why my custom
> view was not drawing properly until I tried turning off hardware
> acceleration.
>
> It is to do with canvas.drawCircle. It is drawn in solid blue at about
> 300px radius.
>
> I also use canvas.drawText and that works fine under hardware acceleration.
>
> The only thing I can think of is that I a using an unsymmetrical
> canvas.scale...
>
> Here is my code:
> // Called to redraw the map
>  @Override
> protected void onDraw(Canvas canvas) {
>  // Check if we are in Eclipse UI editor
> if (isInEditMode()) {
>  return;
> }
>  // Save the canvas' transforms for unscaled UI elements
> canvas.save();
>  // Place the map offset in centre of screen
>  canvas.translate(getWidth() / 2, getHeight() / 2);
>  // Zoom the map
> canvas.scale((float) (-1.0 / mMapController.getMapMetresPerPixelX()),
> (float) (-1.0 / mMapController.getMapMetresPerPixelY()));
>  // Pan the map
> canvas.translate((float) mMapController.getMapCentreX(), (float)
> mMapController.getMapCentreY());
>  // Draw a circle
> canvas.drawCircle(0.0f, 0.0f, 0.01f, mCirclePaint);
>  // Restore the canvas' transforms for unscaled UI elements
>  canvas.restore();
>  // Draw the map centre coordinated and scale in top left
>  canvas.drawText("Centre Coord: (" + String.format("%.4f",
> mMapController.getMapCentreX()) + ", " + String.format("%.4f",
> mMapController.getMapCentreY()) + ")", 16.0f * mDisplayMetrics.density,
> 36.0f * mDisplayMetrics.scaledDensity, mCoordPaint);
>  canvas.drawText("Scale:" + String.format("%.4f",
> mMapController.getMapScale()), 16.0f * mDisplayMetrics.density, 54.0f *
> mDisplayMetrics.scaledDensity, mCoordPaint);
>  }
>
> The values of the various variables from the debugger:
> isInEditMode() = false
> getWidth() = 1080
> getHeight() = 1701
> getMapMetresPerPixelX() = 5.37037039426811E-5
> getMapMetresPerPixelY() = -5.364583215838397E-5
> getMapCentreX() = 0.0
> getMapCentreY() = 0.0
> getMapScale() = 1.0
> mCirclePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
> mCirclePaint.setColor(Color.BLUE);
> mCoordPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
> mCoordPaint.setColor(Color.BLACK);
> mCoordPaint.setTextSize(18.0f * mDisplayMetrics.scaledDensity);
> mDisplayMetrics.density = 3.0
> mDisplayMettrics.scaledDensity = 3.0
>
> I hope that helps figure it out.
>
> I am going to try on the emulator with 4.2 too see what happens.
>
> Leith
>
> --
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Android Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>



-- 
Romain Guy
Android framework engineer
[email protected]

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to