I'm trying to print russian text on printer, but it's not supported, so i decided to print image with text. Here's how i create image with text:
public Bitmap textAsBitmap(String text, float textSize, int textColor) {
Paint paint = new Paint();
paint.setTextSize(textSize);
paint.setColor(textColor);
paint.setAntiAlias(true);
paint.setTypeface(Typeface.SANS_SERIF);
paint.setTextAlign(Paint.Align.LEFT);
//int width = (int) (paint.measureText(text) + 0.5f); // round
int width = 200; // round
float baseline = (int) (-paint.ascent() + 0.5f); // ascent() is negative
//int height = (int) (baseline + paint.descent() + 0.5f);
int height=60;
Log.e("height",height+"");
Log.e("width",width+"");
Bitmap image = Bitmap.createBitmap(width, 2*height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(image);
canvas.drawColor(Color.WHITE);
canvas.drawText(text, 0, baseline, paint);
baseline+=20;
canvas.drawText(text, 0,baseline , paint);
return image;
}
It works fine. But the problem is this chinese printer is printing only 1bit bitmap.So i need a method to convert this image to 1bit bitmap.
I tried this solution
but i got:
but this image is bad(
SOLUTION FOUND I answered myself, see below