fix: accept RX1 encoded BMP dimensions
This commit is contained in:
@@ -89,8 +89,8 @@ android {
|
||||
applicationId = "com.yzx.kiosk"
|
||||
minSdk = 26
|
||||
targetSdk = 36
|
||||
versionCode = 22
|
||||
versionName = "1.1.2"
|
||||
versionCode = 23
|
||||
versionName = "1.1.3"
|
||||
//multiDexEnabled = true
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
|
||||
|
||||
@@ -20,11 +20,11 @@ import jp.co.dnpLib.print.PrintJob
|
||||
import jp.co.dnpLib.print.PrintJobStatus
|
||||
import jp.co.dnpLib.print.PrintManager
|
||||
import jp.co.dnpLib.print.PrintQueue
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
import kotlinx.coroutines.sync.withLock
|
||||
import kotlinx.coroutines.withContext
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
import kotlinx.coroutines.sync.withLock
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import javax.inject.Singleton
|
||||
@@ -42,10 +42,15 @@ class PrinterService(
|
||||
) {
|
||||
companion object {
|
||||
private const val TAG = "PrinterService"
|
||||
|
||||
// DNP BmpUtil 在 300 DPI 下会将 RX1 输入画布编码为 1844x1240 BMP。
|
||||
// 1840x1240 仍是上层排版画布尺寸,不应用它校验 SDK 的最终文件头。
|
||||
private const val RX1_ENCODED_BMP_WIDTH_300_DPI = 1844
|
||||
private const val RX1_ENCODED_BMP_HEIGHT_300_DPI = 1240
|
||||
}
|
||||
|
||||
private var mDnpPhotoPrint: DNPPhotoPrint? = null
|
||||
private val printMutex = Mutex()
|
||||
private var mDnpPhotoPrint: DNPPhotoPrint? = null
|
||||
private val printMutex = Mutex()
|
||||
|
||||
/**
|
||||
* 初始化打印机(耗时操作,需在IO线程调用)
|
||||
@@ -185,14 +190,14 @@ class PrinterService(
|
||||
* @param originalBitmap 要打印的原始图片
|
||||
* @param callback 打印结果回调
|
||||
*/
|
||||
suspend fun startPrint(originalBitmap: Bitmap?, callback: PrintCallback) = printMutex.withLock {
|
||||
startPrintInternal(originalBitmap, callback)
|
||||
}
|
||||
|
||||
private suspend fun startPrintInternal(
|
||||
originalBitmap: Bitmap?,
|
||||
callback: PrintCallback
|
||||
) = withContext(Dispatchers.IO) {
|
||||
suspend fun startPrint(originalBitmap: Bitmap?, callback: PrintCallback) = printMutex.withLock {
|
||||
startPrintInternal(originalBitmap, callback)
|
||||
}
|
||||
|
||||
private suspend fun startPrintInternal(
|
||||
originalBitmap: Bitmap?,
|
||||
callback: PrintCallback
|
||||
) = withContext(Dispatchers.IO) {
|
||||
if (originalBitmap == null) {
|
||||
LogUtils.e(TAG, "获取图片失败")
|
||||
callback.onPrintResult(false,"获取图片失败")
|
||||
@@ -274,10 +279,20 @@ class PrinterService(
|
||||
throw IOException("BMP 保存接口返回失败")
|
||||
}
|
||||
|
||||
val expectedBmpWidth: Int
|
||||
val expectedBmpHeight: Int
|
||||
if (printId != PrintManager.EPrinter.QW410_DEF.id) {
|
||||
expectedBmpWidth = RX1_ENCODED_BMP_WIDTH_300_DPI
|
||||
expectedBmpHeight = RX1_ENCODED_BMP_HEIGHT_300_DPI
|
||||
} else {
|
||||
expectedBmpWidth = printSize.width
|
||||
expectedBmpHeight = printSize.height
|
||||
}
|
||||
|
||||
val validation = PrintImageIntegrityValidator.validateBmp(
|
||||
file = outFile,
|
||||
expectedWidth = printSize.width,
|
||||
expectedHeight = printSize.height
|
||||
expectedWidth = expectedBmpWidth,
|
||||
expectedHeight = expectedBmpHeight
|
||||
)
|
||||
LogUtils.d(
|
||||
TAG,
|
||||
@@ -348,9 +363,9 @@ class PrinterService(
|
||||
// 打印失败,设置为空闲
|
||||
printStatusManager.setIdle()
|
||||
callback.onPrintResult(false,"打印失败: ${e.message}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 打印结果回调接口
|
||||
|
||||
Reference in New Issue
Block a user