Are Android View transformations applied after rasterization?

只谈情不闲聊 提交于 2019-12-10 17:47:03

问题


The lines (A) and the lines (B) in the code below should produce the same image.

Yet lines (A) produce instead the image:

What is happening? Are View/Canvas transformations applied after rasterization?

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.view.View;
import android.graphics.Matrix;

public class MyView extends View {
    Paint paint = new Paint();

    public MyView(Context c) {
        super(c);
        // this.setLayerType(View.LAYER_TYPE_SOFTWARE, null); // (C)
    }

    Rect canvasRect   = new Rect();
    RectF canvasRectf = new RectF();
    RectF scene = new RectF();
    Matrix M = new Matrix();

    @Override
    protected void onDraw(Canvas canvas) {
        getDrawingRect(canvasRect);
        canvasRectf.set(canvasRect);

        scene.set(0,0, 100,100); // (A)
        // scene.set(0,0, 500,500); // (B)

        M.setRectToRect(scene, canvasRectf, Matrix.ScaleToFit.CENTER);
        canvas.setMatrix(M);

        canvas.drawCircle( 50, 50, 1, paint); // (A)
        // canvas.drawCircle(250,250, 5, paint); // (B)
    }
}

Update: If line (C) is uncommented, the problem does not arise (Thanks, Henry). Is it possible to get the first image while using hardware acceleration?


回答1:


I could reproduce the problem only with Android 4.1.2 when hardware acceleration is enabled. Could it be a bug?



来源:https://stackoverflow.com/questions/13996058/are-android-view-transformations-applied-after-rasterization

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!