1

I created CanvasView Object extending View class and I override configChanged in my application's manifest and as you can see, Canvas doesn't redraw again correctly.

  • Portrait:

Portarit

  • Landscape

Landscape

It looks as the rotation doesn't affect the Canvas object.

I've tried invalidting and redrawing again but it doesn't seem to make any difference.

    @Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    super.onSizeChanged(w, h, oldw, oldh);

    if(canvasBitmap == null){
        canvasBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
    }else{
        Bitmap temporary = Bitmap.createScaledBitmap(canvasBitmap, w, h, true);
        canvasBitmap = temporary;
    }
    mCanvas = new Canvas(canvasBitmap);
    draw(mCanvas);
    invalidate();
}

How can I can I keep the Canvas ratio and scaling show it would fit the new size after rotation ?

Gilad Eshkoli
  • 1,253
  • 11
  • 27

1 Answers1

0

I had the same problem but fixed it using the following:

override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
    super.onSizeChanged(w, h, oldw, oldh)
    if(bitMap == null) {
        bitMap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888)
        canvas = Canvas(bitMap)
    } else {
        bitMap = Bitmap.createScaledBitmap(bitMap, w, h, true)
        canvas = Canvas(bitMap)
        canvas.drawBitmap(bitMap, 0f, 0f, bitMapPaint)
    }
}
PygoNode
  • 90
  • 5