I tried to print image and text in receipt using Cpcl format like that template. I have an example set logo as a variable and use function to read the image as string but that image in example is CPCL format I tried a lot to get my logo as a cpcl format but i can't so I need to know how to get my image logo as cpcl format or another way to set image and text like that templete.
====================================================
//this template used to design my ticket which it has image and text in the same ticket like what i need.
! 0 200 200 1050 1
PW 575
TONE 0
SPEED 3
ON-FEED IGNORE
NO-PACE
BAR-SENSE
BT 0 4 6
B 128 3 30 120 20 0 ${barcode}
/* the line below is used to set image as a string variable initialized
in code from image i have in the worked example which its extension
logo.cpcl" I don't know how it comes? and i need to change new logo to
Cpcl from png too "newlogo.png -> newlogo.cpcl" "pcx" x, y, data"*/
PCX 420 790 ${Logo}
ML 32
T270 7 0 550 170 ${typeTicket}
ENDML
ML 32
T270 7 0 498 170 ${validPeriod}
ENDML
ML 25
T270 7 0 446 170 ${park}
ENDML
ML 32
T270 7 0 370 170 ${price}
ENDML
ML 25
T270 7 0 300 170 ${termsOfUse}
ENDML
PRINT
=================================
//this function only to understand what i use to read the image.
[//this line I use to call the function to read cpcl image!
//and here we got the image from resources
result = StringUtils.replace(result, "${Logo}", PrinterUtil.readFormat(context, R.raw.logo));
//this is the code used to read image as a string and it works perfectly with the example.
public static String readFormat(Context context, int formatRes) {
InputStream is = null;
try {
is = context.getResources().openRawResource(formatRes);
try {
return readString(is);
} catch (IOException e) {
return null;
}
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
}
}
}
}][1]
I tried a lot of solution but it doesn't work too. I have old code use image as aلاfile in cpcl extention instead of png or jpg I don't know how it comes? but I created new solution when i searched in documentation i found that command and i did it using the blow steps.
How to change logo in Ticket using CPCL in Android app?
1.You have to follow these steps to change it and make it work with Zebra printer MZ320 & iMZ320:
At the first you have to change your image to black & white image using this link. https://pinetools.com/threshold-image.
After that you have to get it as binary text from its pixels and resize it using custom width =120 using this link https://www.dcode.fr/binary-image.
2.Change all (1) ones in the image to (F) capital letter.
3.your_ticket.cpcl Then you have to use this command into it
`EXPANDED-GRAPHICS [ByteWidth] [Height] [X] [Y] [Data]<CR><LF>`.
4.ByteWidth is size of bytes of first line in your data like that example below.
5.Height is the number of lines in your data
6.Data is the image data copy it from text editor and write it like that example.
7.Example:
EXPANDED-GRAPHICS 10 6 30 30 FFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFFFFFFFFFFF
FF0000FFFFFFF00000FF
FF00000FFFFF000000FF
FF000000FFF0000000FF
FFFFFFFFFFFFFFFFFFFF