From 467d0717125cd45828b60f5e5d7043acfb0f6919 Mon Sep 17 00:00:00 2001 From: Ahmet Inan Date: Fri, 26 Apr 2024 10:51:50 +0200 Subject: [PATCH] update scope view immediately on orientation change --- app/src/main/java/xdsopl/robot36/MainActivity.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/xdsopl/robot36/MainActivity.java b/app/src/main/java/xdsopl/robot36/MainActivity.java index 90e2a49..b058685 100644 --- a/app/src/main/java/xdsopl/robot36/MainActivity.java +++ b/app/src/main/java/xdsopl/robot36/MainActivity.java @@ -382,11 +382,14 @@ public class MainActivity extends AppCompatActivity { } private void createScope(Configuration config) { - int scopeWidth = scopeBuffer.width; - int scopeHeight = scopeBuffer.height / 2; + int width = scopeBuffer.width; + int height = scopeBuffer.height / 2; if (config.orientation == Configuration.ORIENTATION_LANDSCAPE) - scopeHeight /= 2; - scopeBitmap = Bitmap.createBitmap(scopeWidth, scopeHeight, Bitmap.Config.ARGB_8888); + height /= 2; + scopeBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); + int stride = scopeBuffer.width; + int offset = stride * (scopeBuffer.line + scopeBuffer.height / 2 - height); + scopeBitmap.setPixels(scopeBuffer.pixels, offset, stride, 0, 0, width, height); scopeView.setImageBitmap(scopeBitmap); }