Actually i'm trying to make an app for a restaurant waiter,
Now i've added some variant that a waiter can add to a plate but now i'm trying to add a free variant where a waiter can draw manually something like "+Peperoni" and send it to the kitchen.
I'm using this library for draw canvas and now for sending the drawn image i should send a String where every row it's a row of pixels and where if there is no pixels ( white pixel ) i should send 0 and where there is a black dot i should send 1 while if there is a white row for a better performance i shouldn't send anything.
The max sime of the image i can draw is of 512x360 pixel.
Do you have any suggestion on how i can do something like what i would archive? I'm new in android so i even don't know from where to start to write and algorithm like that
Here is code from my CustomAlert where i show the Drawing layout:
public void drawAlert(){
final AlertDialog.Builder mBuilder = new AlertDialog.Builder(this);
@SuppressLint("InflateParams") View mView = getLayoutInflater().inflate(R.layout.alert_drawable, null);
ImageButton del = mView.findViewById(R.id.deleteDraw);
ImageButton draw = mView.findViewById(R.id.drawButton);
final RelativeLayout parentView = mView.findViewById(R.id.parentView);
final CanvasView canvasView = new CanvasView(this);
parentView.addView(canvasView);
mBuilder.setView(mView);
final AlertDialog dialog = mBuilder.create();
dialog.show();
// Here i was trying to make the bitmap as an Array of Bytes but the app crash
draw.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Bitmap bitmap = parentView.getDrawingCache();
ByteArrayOutputStream BAOS = null;
try {
BAOS = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG,100, BAOS);
byte [] b= BAOS.toByteArray();
String temp = Base64.encodeToString(b, Base64.DEFAULT);
Toast.makeText(pterm.this,temp,Toast.LENGTH_LONG).show();
BAOS.close();
} catch (IOException e) {
e.printStackTrace();
}
}
});
del.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
canvasView.clearCanvas();
}
});
}
Crash LOG when i press on "Draw" button:
07-16 12:06:49.447 17910-17910/com.example.igardini.visualposmobile E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.igardini.visualposmobile, PID: 17910 java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.graphics.Bitmap.compress(android.graphics.Bitmap$CompressFormat, int, java.io.OutputStream)' on a null object reference at com.example.igardini.visualposmobile.pterm$24.onClick(pterm.java:702) at android.view.View.performClick(View.java:4781) at android.view.View$PerformClick.run(View.java:19874) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5290) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:911) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:706)