Giter Site home page Giter Site logo

Comments (12)

adelemam avatar adelemam commented on August 17, 2024 1

hi , did any one solved this issue , as i am stuck into it too

from thermal-printer-in-android.

aldyrpl avatar aldyrpl commented on August 17, 2024

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.

Tabicho avatar Tabicho commented on August 17, 2024

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.

aldyrpl avatar aldyrpl commented on August 17, 2024

please can you share the code? i am very stuck

from thermal-printer-in-android.

Tabicho avatar Tabicho commented on August 17, 2024

Now I dont have the code, when I found it I will post it.

from thermal-printer-in-android.

aldyrpl avatar aldyrpl commented on August 17, 2024

i found the answer wait i will check my project

from thermal-printer-in-android.

aldyrpl avatar aldyrpl commented on August 17, 2024

from thermal-printer-in-android.

chukimmuoi avatar chukimmuoi commented on August 17, 2024

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.

bwijayap avatar bwijayap commented on August 17, 2024

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.

jaydeep43 avatar jaydeep43 commented on August 17, 2024

hi.. @chukimmuoi How Can we Define the Right Rows And Cols ?

from thermal-printer-in-android.

chukimmuoi avatar chukimmuoi commented on August 17, 2024

@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.

 avatar commented on August 17, 2024

this documentation will be useful
image

from thermal-printer-in-android.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.