Write text on camera preview

0 votes
asked Jun 7, 2018 by ddeathgame (170 points)

I am using one of the samples provided by EasyAR (HelloARQRCode). As soon as i scan the QR code it shows the toast. Instead of toast I want to show the QR data as text on camera preview. I tried this code using openGL after render() but failed to achieve the results. Any solution?

// Create an empty, mutable bitmap
            Bitmap bitmap = Bitmap.createBitmap(256, 256, Bitmap.Config.ARGB_4444);
// get a canvas to paint over the bitmap
            Canvas canvas = new Canvas(bitmap);
            bitmap.eraseColor(0);
            int[] textures = {1};

 // get a background image from resources
// note the image format must match the bitmap format
            Drawable background = context.getResources().getDrawable(R.drawable.background);
            background.setBounds(0, 0, 256, 256);
            background.draw(canvas); // draw the background to our bitmap

// Draw the text
            Paint textPaint = new Paint();
            textPaint.setTextSize(32);
            textPaint.setAntiAlias(true);
            textPaint.setARGB(0xff, 0x00, 0x00, 0x00);
// draw the text centered
            canvas.drawText("Hello World", 16,112, textPaint);

//Generate one texture pointer...
            GLES20.glGenTextures(1, textures, 0);
//...and bind it to our array
            GLES20.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);

//Create Nearest Filtered Texture
            GLES20.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_NEAREST);
            GLES20.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);

//Different possible texture parameters, e.g. GL10.GL_CLAMP_TO_EDGE
            GLES20.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_REPEAT);
            GLES20.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_REPEAT);

//Use the Android GLUtils to specify a two-dimensional texture image from our bitmap
            GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);

1 Answer

0 votes
answered Jun 8, 2018 by samtae (940 points)
One suggestion: if OR is not used as an imagetarget to display the model, there is no need to use OpenGL to display text content on the screen. This can be done using traditional Android development knowledge. You have compounded the problem by handling it in this way
Welcome to EasyAR SDK Q&A, where you can ask questions and receive answers from other members of the community.
...