光栅化后应用Android设备上查看转换? [英] Are Android View transformations applied after rasterization?

查看:205
本文介绍了光栅化后应用Android设备上查看转换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在code中的线(A)和线(b)所示应该产生同样的图像。

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

然而,线(A)产生,而不是图片:

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)
    }
}

更新:如果线(C)是注释掉,问题就不会出现(感谢,亨利)。是否有可能在使用硬件加速来获得的第一个形象呢?

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?

推荐答案

启用硬件加速时,我只能采用Android 4.1.2重现该问题。难道是一个错误吗?

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

这篇关于光栅化后应用Android设备上查看转换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆