Comments (12)
hi , did any one solved this issue , as i am stuck into it too
from thermal-printer-in-android.
hey sir do you found the answer? because i am stuck in this code for 1 week
if you found the answer i hope you share to me thanks
from thermal-printer-in-android.
Hello, yes What I have to did was divide the image in two images of height no larguer than de allowed then iterate the print process by each part of the image.
from thermal-printer-in-android.
please can you share the code? i am very stuck
from thermal-printer-in-android.
Now I dont have the code, when I found it I will post it.
from thermal-printer-in-android.
i found the answer wait i will check my project
from thermal-printer-in-android.
from thermal-printer-in-android.
You can try the code later:
`private fun splitImage(bitmap: Bitmap, rows: Int, cols: Int) {
try {
// For height and width of the small image chunks.
val chunkHeight = bitmap.height / rows
val chunkWidth = bitmap.width / cols
// Getting the scaled bitmap of the source image.
val scaledBitmap = Bitmap.createScaledBitmap(bitmap, bitmap.width, bitmap.height, true)
// xCoord and yCoord are the pixel positions of the image chunks.
var yCoord = 0
for (x in 0 until rows) {
var xCoord = 0
for (y in 0 until cols) {
val bmp = Bitmap.createBitmap(scaledBitmap, xCoord, yCoord, chunkWidth, chunkHeight)
if (bmp != null) {
val command = EscPosUtils.decodeBitmap(bmp)
outputStream.write(EscPosCommands.ESC_ALIGN_CENTER)
printText(command, false)
} else {
Timber.e("Print Photo error - The file isn't exists")
}
xCoord += chunkWidth
}
yCoord += chunkHeight
}
} catch (e: Exception) {
e.printStackTrace()
}
}`
from thermal-printer-in-android.
Hi @chukimmuoi how can i define the right rows and cols? And what is unit of measure for that? Can you help me to describe it? Please help
from thermal-printer-in-android.
hi.. @chukimmuoi How Can we Define the Right Rows And Cols ?
from thermal-printer-in-android.
@jaydeep43 @BayuWijayaPermanaPutra Sorry, cols = 1 and row = bmpScale.height / 32 + 1. This is full code, no need to care typePrint:
private fun printText(msg: ByteArray, isNewLine: Boolean = true) {
outputStream?.let {
try {
it.write(msg) // Print normal text.
} catch (e: IOException) {
e.printStackTrace()
}
}
}```
```// Print bill.
private fun printWebView(bmpScale: Bitmap, typePrint: Int) {
try {
val isPrintCook = typePrint == QueueDataPrint.VALUE_PRINT_COOK
val isOpenCashBox = typePrint == QueueDataPrint.VALUE_PRINT_CASHIER
fun innerHandler(rows: Int) {
splitImage(bmpScale, rows, 1) {
printText(it, false)
}
autoCut(isOpenCashBox)
}
if (bmpScale != null) {
val rows = bmpScale.height / 32 + 1
outputStream?.write(EscPosCommands.ESC_ALIGN_CENTER)
innerHandler(rows)
if (preferencesHelper.getPrintTwoForInvoice() && !isPrintCook)
innerHandler(rows)
} else {
Timber.e("Print Photo error - the file isn't exists")
}
} catch (e: Exception) {
e.printStackTrace()
Timber.e("PrintTools - the file isn't exists")
}
}```
```private fun splitImage(bitmap: Bitmap, rows: Int, cols: Int, doAction: (ByteArray) -> Unit) {
synchronized(this) {
try {
// For height and width of the small image chunks.
var chunkHeight = bitmap.height / rows + 1
val chunkWidth = bitmap.width / cols
// Getting the scaled bitmap of the source image.
val scaledBitmap = Bitmap.createScaledBitmap(bitmap, bitmap.width, bitmap.height, true)
// xCoord and yCoord are the pixel positions of the image chunks.
var yCoord = 0
for (x in 0 until rows) {
var xCoord = 0
for (y in 0 until cols) {
if (yCoord + chunkHeight > bitmap.height) {
chunkHeight = bitmap.height - yCoord
}
val bmp = Bitmap.createBitmap(scaledBitmap, xCoord, yCoord, chunkWidth, chunkHeight)
if (bmp != null) {
val command = EscPosUtils.decodeBitmap(bmp)
doAction(command)
} else {
Timber.e("Print Photo error - The file isn't exists")
}
xCoord += chunkWidth
}
yCoord += chunkHeight
}
} catch (e: Exception) {
e.printStackTrace()
}
}
}```
from thermal-printer-in-android.
this documentation will be useful
from thermal-printer-in-android.
Related Issues (20)
- Coding android to print Thai character on Bluetooth printer
- Work in MPT III? HOT 1
- Printing large height HOT 2
- can we stop printing the logs while connecting and disconneting
- W/System.err: java.io.IOException: read failed, socket might closed or timeout, read ret: -1 HOT 2
- How can I keep connection with thermal printer even if the activity destroyed or application closed ? HOT 1
- How to align image to center? HOT 1
- "Cannot establish connection" HOT 6
- Print image via bluetooth printer
- Application Not Working after creating APK from android studio
- Multiple connection
- DeviceList is empty
- cannot print, establish connection HOT 2
- How to Print Two Different Text Alignment on same line ? For invoice HOT 2
- Align Image in center HOT 3
- This code will work for all types of printer? HOT 1
- Printer Hindi language does not supported. - Thermal-Printer-in-Android HOT 2
- Pdf support HOT 1
- External app communication
- multiple printers
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from thermal-printer-in-android.