This took a little bit to find but the problem I am having is that the
matrix I setup for the canvas does not work on scaling the rendering
calls when it reaches a certain scaling resolution. But if I manually
use the Matrix to convert the values and then call the rendering calls
it works fine.

1. I have verified that this problem is in both cupcake and donut.
2. Create a custom view
3. Override onDraw
4. Create an onDraw like below.
5. The scaling factor 2.4414E-4f will make the canvas NOT use the
matrix appropriately while 2.44141E-4 will make everything turn out
fine.

@Override
protected void onDraw(final Canvas canvas)
{
        super.onDraw(canvas);

        final DisplayMetrics metrics = getContext().getApplicationContext
().getResources().getDisplayMetrics();

        final float scaleFactor = 2.4414E-4f; // 2.44141E-4f will render
properly
        final float genUnits = metrics.xdpi / scaleFactor;

        final float sx = scaleFactor;
        final float sy = scaleFactor;

        final float left = 0.5f * genUnits;
        final float top = 0.5f * genUnits;
        final float right = left + genUnits;
        final float bottom = top + genUnits;

        final RectF rectF = new RectF(left, top, right, bottom);

        final Paint paint = new Paint();
        paint.setAntiAlias(true);
        paint.setColor(android.graphics.Color.BLUE);
        paint.setStyle(Paint.Style.FILL);

         canvas.save();
         canvas.scale(sx, sy);
         canvas.drawRect(rectF, paint);
         canvas.restore();
}

If you replace the last four lines of code with the following code
which uses the matrix to scale the coordinates manually, then you will
see that the object renders regardless of what scaling factor you are
using in the Matrix.

canvas.save();
final Matrix mtx = new Matrix();
mtx.preScale(sx, sy);
mtx.mapRect(rectF);
canvas.drawRect(rectF, paint);
canvas.restore();

This implies that there is an issue with the Canvas Matrix
transformation code. Not sure if there is some kind of error being
thrown in the internals or what, but the small difference in that
scale factor makes rendering to the canvas stop working properly.

This is a pretty big issue since now if you want to use those kind of
scaling factors you have to scale all of your points manually instead
of just letting the Canvas handle it appropriately, which means either
wrapping all of the Canvas APIs or spreading coordinate conversion
code throughout.

Has anyone else seen this? Is this slated for a fix?

Thanks in advance for your response,

Keith

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to