I have found an solution for this problem. Everytime the screen orientation changed the event was being called. So the bitmap was recreated everytime. I have fixed this by scaling the bitmap before recreation and then setting it as new bitmap. This way it is automatticly scaled and nothing is lost. This is the full code now:
private Canvas drawCanvas;
private Bitmap canvasBitmap;
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
//View given size
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;
}
drawCanvas = new Canvas(canvasBitmap);
}