位图不在画布上显示

时间:2016-05-10 14:32:06

标签: android view bitmap android-canvas android-bitmap

对这样一个基本问题道歉。我一直在尝试将我的图像资源解码为位图,然后在我的customView中将其绘制到我的画布上。

我已将此问题与几个类似的Stackoverflow问题进行了比较,并尝试了其他方法,但没有运气显示图像。

public class CircleView extends View implements View.OnTouchListener{


private Paint baseCircle, touchCircle;
private int xInput, yInput;
private int width, height;
private float circleCenterX, circleCenterY, circleRadius;
private Resources res;
private Bitmap bitmap;


public CircleView(Context context){
    super(context);

    res = getResources();
    bitmap = BitmapFactory.decodeResource(res, R.drawable.wheel);

    width = Resources.getSystem().getDisplayMetrics().widthPixels;
    height = Resources.getSystem().getDisplayMetrics().heightPixels;
    circleCenterX = width/2;
    circleCenterY = height/2;
    circleRadius = 500;

    baseCircle = new Paint();
    baseCircle.setColor(Color.GRAY);

    touchCircle = new Paint();
    touchCircle.setAntiAlias(true);
    touchCircle.setColor(Color.RED);

    setFocusable(true);
    this.setOnTouchListener(this);

}

@Override
protected void onDraw(Canvas canvas){
    canvas.drawCircle(circleCenterX, circleCenterY, circleRadius,baseCircle);
    canvas.drawCircle(xInput, yInput, 50, touchCircle);
    canvas.drawBitmap(bitmap, 0, 0, null);
}

0 个答案:

没有答案