Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unwanted Warp effect drawing text on path android

I do some tests on drawing text on path. I made a background picture by setting bitmap to the canvas. Then, I draw text on a path to canvas, rotated by matrix. I have to shorten the code, I will only post the important part because it is too long. This images shown below are cropped with gimp, so don´t be irritated by the different sizes. My Rect, Path and Matrix objects:

    RectF drawTextOval;
    Path drawTextPath;
    Matrix mDrawnMatrix;

Now, this is what I am doin to draw text on circle path:

    drawTextOval.set(drawTextPosX - drawTextArc, drawTextPosY
                    - drawTextArc, drawTextPosX + drawTextArc, drawTextPosY
                    + drawTextArc);
            drawTextPath.addArc(drawTextOval, 0, 360);

            drawTextPath.computeBounds(drawTextOval, true);
            mDrawnMatrix.postRotate(drawTextArcStart,
                    (drawTextOval.right + drawTextOval.left) / 2,
                    (drawTextOval.bottom + drawTextOval.top) / 2);
            drawTextPath.transform(mDrawnMatrix);

            patternCanvas.drawTextOnPath(drawText, drawTextPath, 0, 0,
                    mFixedTextPaint); 

Until this point, everything looks fine:

enter image description here

But after saving the whole screen, the rotated text looks warped at the saved .png image. All the other components looking good. I made some other drawings with text, linear or angular, all this works. Even some .png bitmaps drawing to canvas and the background image...all are looking normally. But the on circle path drawn text looks like this:

enter image description here

I don´t do any scaling on the bitmap, just saving the canvas image with:

    FileOutputStream fos = new FileOutputStream(saveFile);
        this.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);
        Bitmap bitmap = this.getDrawingCache();


        bitmap.compress(CompressFormat.PNG, 100, fos);
        fos.flush();
        fos.close();

Why does the text look warped? Does anyone see my mistake? Thanks in advance...

EDIT

I tried some stuff and find out that setting any density to false or disable hardware acceleration in Manifest will show the effect at runtime before saving. That suggests to me, that when saving bitmap with getDrawingCache(), the scaling is disabled at this time. But why?

The last thing I found out, that the lower the curvature the lower is the text scaling. If the text is just a little bit curved, it seems good.

enter image description here

like image 949
Opiatefuchs Avatar asked May 20 '13 18:05

Opiatefuchs


1 Answers

I would try setting the

this.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH);

before drawing to screen, since lower quality might imply a simpler transformation of the text. This is just guessing of course. Currently your only setting the high quality before writing to disk. Or simply remove it from the write to disk method to check if it affect the way the text is drawn.

like image 106
Carl-Emil Kjellstrand Avatar answered Oct 17 '22 15:10

Carl-Emil Kjellstrand