'Sending images to the network for screen transmission

How can I send the captured image to the network using libstreaming? I need to stream the screen from android to a website. I don't know where in my code I can implement this solution. Would it be after generating byte arrays of images?

private void createVirtualDisplay() {

        Log.d("TAG", "createVirtualDisplay...................");

        // get width and height / obtem largura e altura
        mWidth = Resources.getSystem().getDisplayMetrics().widthPixels / 4;
        mHeight = Resources.getSystem().getDisplayMetrics().heightPixels / 4;   
       
        mImageReader = ImageReader.newInstance(mWidth, mHeight, PixelFormat.RGBA_8888, 2);

        mVirtualDisplay = mMediaProjection.createVirtualDisplay(SCREENCAP_NAME, mWidth, mHeight,
                mDensity, getVirtualDisplayFlags(), mImageReader.getSurface(), null, mHandler);

        mImageReader.setOnImageAvailableListener(new ImageAvailableListener(), mHandler);
    }

private class ImageAvailableListener implements ImageReader.OnImageAvailableListener {
        @Override
        public void onImageAvailable(ImageReader reader) {

            Log.d("TAG", "onImageAvailable...................");

            FileOutputStream fos = null;
            Bitmap bitmap = null;
            try (Image image = mImageReader.acquireLatestImage()) {
                if (image != null) {
                    Image.Plane[] planes = image.getPlanes();
                    ByteBuffer buffer = planes[0].getBuffer(); //o buffer de bytes contendo os dados de imagem para este plano
                    int pixelStride = planes[0].getPixelStride(); //Esta é a distância entre dois valores de pixel consecutivos em uma linha de pixels
                    int rowStride = planes[0].getRowStride(); //Esta é a distância entre o início de duas linhas consecutivas de pixels na imagem
                    int rowPadding = (rowStride - pixelStride * mWidth);

                    // create bitmap
                    bitmap = Bitmap.createBitmap(mWidth + rowPadding / pixelStride, mHeight, Bitmap.Config.ARGB_8888);
                    bitmap.copyPixelsFromBuffer(buffer);



                    IMAGES_PRODUCED++;
                    Log.e(TAG, "captured image: " + IMAGES_PRODUCED);

                    //TRANSFOMAR BITMAP EM ARRAY DE BYTES
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    bitmap.compress(Bitmap.CompressFormat.JPEG, 20, baos);

                    byte[] dadosImagem = baos.toByteArray();


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source