I get an error of
java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
at com.kotlin.ambulantlcs.helpers.PrinterHelper.getTrasparentBitmapCopy(PrinterHelper.java:145)
at com.kotlin.ambulantlcs.helpers.PrinterHelper.convertStringToImage(PrinterHelper.java:133)
when I run this code in Android Java
public static void convertStringToImage(Activity activity)
{
Bitmap bitmap = Bitmap.createBitmap(300, 400, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.drawColor(Color.BLACK);
Paint paint = new Paint();
paint.setTextAlign(Paint.Align.LEFT);
paint.setAntiAlias(true);
paint.setTextSize(12);
canvas.drawText("Lorem Ipsum Dolor Sed Actum Malo", 10, 10, paint);
canvas.save();
canvas.restore();
int iRet = ftplib.printPicture(bitmap, FTPAndroidLib.DITHER_NONDITHERING, bitmap.getHeight(), bitmap.getWidth()); ===> ERROR IS HERE
}
I am trying to create an image of a text that I create programmatically because I will be joining it to another image later. But before I do that, I am printing it out first.
Edit
Bitmap bitmap = Bitmap.createBitmap(200, 100, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.drawColor(Color.WHITE);
Paint paint = new Paint();
paint.setTextAlign(Paint.Align.LEFT);
paint.setAntiAlias(true);
paint.setTextSize(9);
canvas.drawPaint(paint);
paint.setColor(Color.BLACK);
paint.setTextSize(9);
canvas.drawText("Lorem Ipsum Dolor Sed Actum Malo", 0, 50, paint);
canvas.save();
canvas.restore();
int iRet = ftplib.printPicture(bitmap, FTPAndroidLib.DITHER_NONDITHERING, bitmap.getWidth(), bitmap.getHeight());
Edit 2
Bitmap bitmap = Bitmap.createBitmap(350, 200, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.drawColor(Color.WHITE);
Paint paint = new Paint();
paint.setColor(Color.BLACK);
paint.setTextAlign(Paint.Align.LEFT);
paint.setAntiAlias(true);
paint.setTextSize(20);
Log.i("TAG", message);
canvas.drawText("Lorem Ipsum Dolor Sed Actum Malo", 0, 50, paint);
canvas.save();
int iRet = ftplib.printPicture(bitmap, FTPAndroidLib.DITHER_NONDITHERING, bitmap.getWidth(), bitmap.getHeight());