From 85d596f610e64c2accc0d8ac9adb6ed7b0fe7139 Mon Sep 17 00:00:00 2001 From: it232115 Date: Fri, 19 Jan 2024 06:35:32 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=87=E3=83=90=E3=82=A4=E3=82=B9=E3=81=AB?= =?UTF-8?q?=E3=82=88=E3=81=A3=E3=81=A6QR=E7=94=BB=E5=83=8F=E3=81=AE?= =?UTF-8?q?=E3=82=B5=E3=82=A4=E3=82=BA=E3=81=8C=E5=A4=A7=E3=81=8D=E3=81=8F?= =?UTF-8?q?=E9=81=95=E3=81=86=E3=83=90=E3=82=B0=E3=81=AE=E4=BF=AE=E6=AD=A3?= =?UTF-8?q?(=E3=83=86=E3=82=B9=E3=83=88=E3=81=AF=E3=81=97=E3=81=A6?= =?UTF-8?q?=E3=81=84=E3=81=AA=E3=81=84=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/example/childguard/QrUtils.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/example/childguard/QrUtils.java b/app/src/main/java/com/example/childguard/QrUtils.java index dc4f493..48b6460 100644 --- a/app/src/main/java/com/example/childguard/QrUtils.java +++ b/app/src/main/java/com/example/childguard/QrUtils.java @@ -8,7 +8,9 @@ import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.drawable.BitmapDrawable; import android.util.AndroidRuntimeException; +import android.util.DisplayMetrics; import android.util.Log; +import android.view.WindowManager; import android.widget.ImageView; import androidx.print.PrintHelper; @@ -35,6 +37,7 @@ public class QrUtils { AllURL=KoteiURL+key; int size = 1500; + int qrCodeSize = calculateQRCodeSize(); // 画面密度に応じてサイズを計算 Bitmap QRGazou; Bitmap bitmapqr; try { @@ -55,10 +58,21 @@ public class QrUtils { // 画像のサイズの調整 int disWidth = (width - bitmapqr.getWidth()) / 2; - int disHeight = (int) ((height - bitmapqr.getHeight()) / 1.3); + int disHeight = (int) ((height - bitmapqr.getHeight()) / 1.4); canvas.drawBitmap(bitmap, 0, 0, (Paint) null); canvas.drawBitmap(bitmapqr, disWidth, disHeight, (Paint) null); // 画像合成 //Androidからプリンターへ印刷指示を出すサポートライブラリ return QRGazou; } + private int calculateQRCodeSize() { + // 画面解像度を取得 + DisplayMetrics metrics = new DisplayMetrics(); + WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); + windowManager.getDefaultDisplay().getMetrics(metrics); + + // 画面密度に基づいてQRコードのサイズを計算 + float density = context.getResources().getDisplayMetrics().density; + return (int) (1500 * density); + } + }