-
-
Notifications
You must be signed in to change notification settings - Fork 351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Performance optimization of EscPosPrinterCommands.bitmapToBytes() logic #490
Comments
Thanks for this tips, CPU use versus RAM use... I don't know which is better. Your code can crash on low memory devices. Perhaps the right compromise is to get pixels row by row. I will think about it. 256px height limitation is because bigs pictures crash on many printers (Error : Buffer not large enough for pixels). Or with bluetooth, too many data send print characters instead of image (I think some data is lost but we can't have feedback of printer to have the error). |
I have tested the two different models of printers I currently have on hand, under high load testing for some time, and so far there has been no crash problem. Yeah, you remind me, I haven't considered the use case for low memory devices yet. Maybe introducing a thread pool to process this conversion logic in parallel is a feasible solution, I guess. |
Hi, I just used this library today to implement the bitmap print feature. It helped me a lot. Great work! But there is a small piece of code that might need to be improved.
I found that the
bitmapToBytes
function is performing very slowly. I looked through the source code and found that there is no need to callbitmap.getPixel(posX, posY)
in every iteration, as this is a time-consuming operation. Instead, we can obtain the entire pixel array outside of the iteration and get the corresponding color information from this array within each iteration.I have tested this modification and it has significantly improved the processing performance of this function.
The updated code is as follows:
The bigger the bitmap, the more significant the effect
Besides, there is no need to limit the maximum height of the printed image and break it down into smaller parts for printing. Parsing it as a whole one time is enough. This will save more time.
I extracted the
bitmapToBytes
function to use in my project and didn't break the bitmap down. It printed very fast with no problems. I didn't even resize the bitmap.The text was updated successfully, but these errors were encountered: