Open lavahasif opened 4 years ago
Hi @lavahasif I'm misconfused about "can you suggest to preview escposImage as image file" Are you asking about I have one UI viewer of escpos-image dump? or are you asking if it can send the dump to one file?
However, in my point of view, first we need to isolate the problem. The problem can be simulated? If yes, I can help you to debug and find the problem.
if not: In my analisis, the problem can happen on some groups, and you can dump file results the variables: bitmap imageWrapper TcpIpOutputStream
RasterBitImageWrapper imageWrapper = new RasterBitImageWrapper();
Bitonal algorithm = new BitonalOrderedDither();
EscPosImage escposImage = new EscPosImage(new CoffeeImageAndroidImpl(bitmap), algorithm);
escpos.write(imageWrapper, escposImage);
// save imageWrapper to one file to print...
byte[] bytes = imageWrapper.getBytes(escposImage);
// create one file and save it...
// save the bitmap to another file (png)
them, when the problem happen, Analising the files, you can conclude where the problem is.
count on me, Marco
Thank you for your quick replay.
### {I'm misconfused about "can you suggest to preview escposImage as image file" Are you asking about I have one UI viewer of escpos-image dump? or are you asking if it can send the dump to one file?}
yes I want to save the esposimage variable as a image file for checking(I have one UI viewer of escpos-image dump) .some time the pritnting not work properly (https://user-images.githubusercontent.com/22430922/90307980-2bb92b80-def9-11ea-8823-2a6388d3a844.jpeg ) not always . so i want to check where it happen.
I made one variant of EscPos Class, you can use it to dump file content on android
You can use traditional write that only dump the escpos_image, or one more complete function version writeAndDumpFiles that dump the escpos image and dump the Bitmap too..
I hope this help you. till later.
package com.github.anastaciocintra.escposcoffeesamples.androidimage;
import android.content.Context;
import android.graphics.Bitmap;
import com.github.anastaciocintra.escpos.EscPos;
import com.github.anastaciocintra.escpos.image.Bitonal;
import com.github.anastaciocintra.escpos.image.EscPosImage;
import com.github.anastaciocintra.escpos.image.ImageWrapperInterface;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
public class EscposWithDumpAndroid extends EscPos {
private Context context;
/**
* creates an instance based on outputStream.
*
* @param outputStream can be one file, System.out or printer...
* @see OutputStream
*/
public EscposWithDumpAndroid(OutputStream outputStream, Context context) {
super(outputStream);
this.context = context;
}
@Override
public EscPos write(ImageWrapperInterface wrapper, EscPosImage image) throws IOException {
// call original write
super.write(wrapper, image);
DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
String strDate = dateFormat.format(new Date());
String fileName = strDate + ".dump";
// creating file...
// https://developer.android.com/training/data-storage/app-specific
FileOutputStream fileDump = context.openFileOutput(fileName, Context.MODE_PRIVATE);
// dump escpos_image
byte[] bytes = wrapper.getBytes(image);
fileDump.write(bytes);
// close file
fileDump.close();
return this;
}
// other and more complete option
// dump both files, the EscposImage and the bitmap
public EscPos writeAndDumpFiles(ImageWrapperInterface wrapper, Bitonal algorithm, Bitmap bitmap) throws IOException {
EscPosImage escposImage = new EscPosImage(new CoffeeImageAndroidImpl(bitmap), algorithm);
super.write(wrapper, escposImage);
DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
String strDate = dateFormat.format(new Date());
String fileName = strDate + ".dump";
// creating file...
// https://developer.android.com/training/data-storage/app-specific
FileOutputStream fileDump = context.openFileOutput(fileName, Context.MODE_PRIVATE);
// dump escpos_image
byte[] bytes = wrapper.getBytes(escposImage);
fileDump.write(bytes);
// close file
fileDump.close();
// Bitmap
fileName = strDate + ".png";
fileDump = context.openFileOutput(fileName, Context.MODE_PRIVATE);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, fileDump);
fileDump.close();
return this;
}
}
Hi @lavahasif recently, i discovered that if the image have width or height bigger than printer supported, then can happen this, one overflow, and the printer output will be unpredictable.
You can log the image dimensions to diagnose if is this happening.
Hi @lavahasif recently, i discovered that if the image have width or height bigger than printer supported, then can happen this, one overflow, and the printer output will be unpredictable.
You can log the image dimensions to diagnose if is this happening.
Thank you for your effort.Some time i feel it.i already mention above .For checking i print 20 page simultaneously .i did'nt get any garbage .some time get above character.my customer have daily 300 bills.some time they get garbage print.so i change the above model now i am using printer font with logo now no problem.some time i feel may be my app have memory leak(if i get garbage then i try to restart the printer then take bill get correctly). Due to that reason some time getting that print.Thanks Could you suggest any method accessing shared printer from windows in android.(now i am using webapi selfhosted service to maintain the problem)
Hi @lavahasif recently, i discovered that if the image have width or height bigger than printer supported, then can happen this, one overflow, and the printer output will be unpredictable.
You can log the image dimensions to diagnose if is this happening.
My printing Method was :-
Collect Printing Data --->Convert to html (width 300px 'variation get big or overflow print(i didnt get any garbage )'-->html to image(Here i try to save 60 or above continous save bill to internal storage no problem )-->escpos
hi, i have the same problem, in my case it only works for the first time after i turn on the printer, and then only print random charatcters. My solution is this: after i create escpos object then i call escPos.initializePrinter(); and after a the full printing proces i call it once again before close: escPos.flush();escPos.initializePrinter();escPos.close(); And it wokrs for me, but its not perfect because the justification is not ok... And of course it depends on the printer eg on the sam4s printer works fine without any tricks, and a on chinise noname printer i need this tricks above
print 20 print continuos no problem but some time some time showing this anyway thank you for solution helped
code: public void run(String ip, Bitmap bmp, PrintBillFormat printBillFormat) { String host = ip; int port = 9100; try (TcpIpOutputStream stream = new TcpIpOutputStream(host, port)) { EscPos escpos = new EscPos(stream);
can you suggest to preview escposImage as image file