1

Hi apologies for such a basic question. I've been trying to decode my image resource into a bitmap and draw it onto my canvas within my customView.

I've compared this issue to several similar Stackoverflow questions and have tried other methods but have had no luck displaying the image.

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);
}
Patryk
  • 279
  • 1
  • 10

0 Answers0