-
-
Notifications
You must be signed in to change notification settings - Fork 367
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
Size of the image #70
Comments
You have to generate a bitmap in the good dpi and size. |
I am still facing the same issue. can you share a sample code for generating that picture passing base64 string? |
We managed to get the image print at full width, but i think there is a height restriction, we want to print the image at its full height. here is the code we did:
As you can see in the picture, in the left i made the height of the bitmap larger the the width, but the right side one i made the height less than width, which made it have the full width of the paper. |
Yes, you have to split every 256px. |
Thanks, i managed to do it with the following code:
The only problem is that each split have a space after, it seems that the img tag is causing this, any solution? |
Tried it, still the same problem |
Great but you do it wrong. new Thread(new Runnable() {
public void run() {
try {
byte[] decodedString = Base64.decode(receipt, Base64.DEFAULT);
List<Bitmap> segments = new ArrayList<Bitmap>();
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
int width = decodedByte.getWidth();
int height = decodedByte.getHeight();
for(int y = 0; y < height; y += 256) {
y = y >= height? height : y;
int limit = y + 256 >= height? height - y : 256;
Bitmap bitmap = Bitmap.createBitmap(decodedByte, 0, y, width, limit);
segments.add(bitmap);
}
TcpConnection tcpConnection = new TcpConnection(ipAddress.getText().toString(), Integer.parseInt(portAddress.getText().toString()));
EscPosPrinter printer = new EscPosPrinter(tcpConnection, 201, 77f, 1);
StringBuilder printText = new StringBuilder();
for (Bitmap segment : segments) {
printText.append("[C]<img>" + PrinterTextParserImg.bitmapToHexadecimalString(printer, segment) + "</img>\n");
}
printText.append("[C]Printed!!!\n");
printer.printFormattedTextAndCut(printText.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
}).start(); |
Tried this solution, still the same problem unfortunately. |
Very weird, this should works. :/ Try this : new Thread(new Runnable() {
public void run() {
try {
TcpConnection tcpConnection = new TcpConnection(ipAddress.getText().toString(), Integer.parseInt(portAddress.getText().toString()));
EscPosPrinter printer = new EscPosPrinter(tcpConnection, 203, 70f, 48);
byte[] decodedString = Base64.decode(receipt, Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
int width = decodedByte.getWidth(), height = decodedByte.getHeight();
StringBuilder textToPrint = new StringBuilder();
for(int y = 0; y < height; y += 256) {
Bitmap bitmap = Bitmap.createBitmap(decodedByte, 0, y, width, (y + 256 >= height) ? height - y : 256);
textToPrint.append("[C]<img>" + PrinterTextParserImg.bitmapToHexadecimalString(printer, bitmap) + "</img>\n");
}
textToPrint.append("[C]Printed!!!\n");
printer.printFormattedTextAndCut(textToPrint.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
}).start(); |
Do you find the solution ? |
I don't understand where does this spaces come from. |
I think it's something related to the '\n' making margin between each img tag, not sure though. I tried many solutions but no luck so far |
\n is just use for spliting line. There are not printed. |
I got the same problem. It scales the image to maxHeight of 255. |
yes i know and is not an issue. |
Same problem for me here. One thing I noticed is that if i split every 256px (or 128 and probably true for other powers of 2) I get a much bigger space than if i split every 255px (or 127). I could also guess that the printer is adding the extra space after each image, but printing images using some other applications from the play store work fine, and I also guess that they also have to handle this max height of 256 pixels - but I could be totally wrong here. |
The problem is here: http://prntscr.com/vdcdqd
Add params newLine. |
Instead of your extra param newLine, try this ;) for (PrinterTextParserLine line : linesParsed) {
PrinterTextParserColumn[] columns = line.getColumns();
IPrinterTextParserElement lastElement = null;
for (PrinterTextParserColumn column : columns) {
IPrinterTextParserElement[] elements = column.getElements();
for (IPrinterTextParserElement element : elements) {
element.print(this.printer);
lastElement = element;
}
}
if(!(lastElement instanceof PrinterTextParserImg) && !(lastElement instanceof PrinterTextParserBarcode)) {
this.printer.newLine();
}
} |
say me if it works, I will publish a new release ! |
@DantSu Do you solve the problem ? |
@DantSu this solution work for me , you can update library with this solution |
Ok thx i will publish a new release. |
Ok v2.0.7 is out. |
I can confirm this release fixed the issue. |
If you only print image and do not use formatted text, you can do that :The image must have a correct width :
int targetWidth = 383; // 48mm printing zone with 203dpi => 383px
Bitmap rescaledBitmap = Bitmap.createScaledBitmap(
originalBitmap,
targetWidth,
Math.round(((float) originalBitmap.getHeight()) * ((float) targetWidth) / ((float) originalBitmap.getWidth())),
true
);
EscPosPrinterCommands printerCommands = new EscPosPrinterCommands(BluetoothPrintersConnections.selectFirstPaired());
try {
printerCommands.connect();
printerCommands.reset();
printerCommands.printImage(EscPosPrinterCommands.bitmapToBytes(rescaledBitmap));
printerCommands.feedPaper(50);
printerCommands.cutPaper();
} catch (EscPosConnectionException e) {
e.printStackTrace();
} |
this work for width of image but some of height not printed |
it work fine when increase feed , nice solution thanks |
@DantSu when try print bitmap image |
I think the error message is explicit.... your printer haven't enougth memory for the image you try to print... |
@DantSu thanks for reply just print image 60*60. POS device type Aisino A90 |
Try to use Method : useEscAsteriskCommand(boolean enable)Active "ESC *" command for image printing.
|
@DantSu this is my code
|
@DantSu |
Cant help you more |
@DantSu thanks i fix isssue |
How ? |
@DantSu |
Hi my image is accurate. but the quality of the image is too low i am using this below code
|
to get full sized bitmap, use this code in EscPosPrinterSize class.
|
Inreasing feed did not work for me. Actually it looks like any parameter passed to feedPaper is ignored for the printer i use. |
If someone still facing this issue, i am using a simpler solution... Just create new class that extends EscPosPrinterSize package com.yourpackage.name import android.graphics.Bitmap class CustomEscPosPrinterSize(i: Int, fl: Float, i1: Int) : EscPosPrinterSize(i, fl, i1) {
} Following Code is Removed / Commented which was causing Height Issues in original lib |
Hello
Is there any way to make the image large?
I have base64 image that I convert to bitmap and then pass it to bitmapToHexadecimalString.
Ex.
The text was updated successfully, but these errors were encountered: