0

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.

enter image description here

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)

NiceToMytyuk
  • 3,644
  • 3
  • 39
  • 100
  • 1
    What about sending screen shot of the canvas? – B001ᛦ Jul 16 '18 at 09:43
  • 2
    Why would you want this? The reason everyone uses POS systems is because nobody could actually read hand written tickets, bad handwriting was the cause of 90% of order errors. Using fingers to draw would be even worse, its sloppier. Adding a way for them to add text would make much more sense. – Gabe Sechan Jul 16 '18 at 09:43
  • @GabeSechan actually i've said it more and more times to my head but he anyway want it because it "impresses" the client's. And yes i have yet the possibility to add text but the head still want to be able to draw -_- – NiceToMytyuk Jul 16 '18 at 09:46
  • I was thinking about this topic technically--- but in fact @GabeSechan said all – B001ᛦ Jul 16 '18 at 09:47
  • @B001ᛦ i'll have to send it to a server that should fastly print it on a POS printer so making a screen sending it to the server which will transform it to a readable image will take longer time – NiceToMytyuk Jul 16 '18 at 09:47
  • 1
    @JohnKarry i would quit my job in such a case, tell your head the client is stupid! – Yamen Nassif Jul 16 '18 at 09:58
  • 1
    @YamenNassif i would but i'm just 18 and it's my first job so trying to do my best – NiceToMytyuk Jul 16 '18 at 10:02
  • 1
    keep it up then ^^ – Yamen Nassif Jul 16 '18 at 10:02
  • 1
    just a thought accord to me, since canvas is hold in a bitmap you can get a bytearray out of that bitmap easily https://stackoverflow.com/a/4989543/2724879 and then you can send it as a stream, string or what so ever you want – Yamen Nassif Jul 16 '18 at 10:09
  • @YamenNassif actually i was trying to do something like that as you can see on my updated answer and even trying the solution of what you've sent but still the app crashing with the same error, the problem is that the object is not null – NiceToMytyuk Jul 16 '18 at 10:14
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/176044/discussion-between-yamen-nassif-and-johnkarry). – Yamen Nassif Jul 16 '18 at 10:14

0 Answers0