Exemplo n.º 1
0
        public void OnImageAvailable(ImageReader reader)
        {
            Android.Media.Image image = null;

            Android.Graphics.Bitmap bitmap = null;
            try
            {
                image = reader.AcquireLatestImage();
                if (image != null)
                {
                    Image.Plane[] planes      = image.GetPlanes();
                    ByteBuffer    buffer      = planes[0].Buffer;
                    int           offset      = 0;
                    int           pixelStride = planes[0].PixelStride;
                    int           rowStride   = planes[0].RowStride;
                    int           rowPadding  = rowStride - pixelStride * ForegroundService.mWidth;
                    // create bitmap
                    bitmap = Android.Graphics.Bitmap.CreateBitmap(ForegroundService.mWidth + rowPadding / pixelStride, ForegroundService.mHeight, Android.Graphics.Bitmap.Config.Argb8888);
                    bitmap.CopyPixelsFromBuffer(buffer);
                    image.Close();
                    using (System.IO.MemoryStream fos = new System.IO.MemoryStream())
                    {
                        bitmap.Compress(Android.Graphics.Bitmap.CompressFormat.Jpeg, kalite, fos);
                        byte[] dataPacker = ForegroundService._globalService.MyDataPacker("LIVESCREEN", StringCompressor.Compress(fos.ToArray()), ID);
                        try
                        {
                            if (screenSock != null)
                            {
                                screenSock.Send(dataPacker, 0, dataPacker.Length, SocketFlags.None);
                                System.Threading.Tasks.Task.Delay(1).Wait();
                            }
                        }
                        catch (Exception) { }
                    }
                }
            }
            catch (Exception ex)
            {
                try
                {
                    byte[] dataPacker = ForegroundService._globalService.MyDataPacker("ERRORLIVESCREEN", System.Text.Encoding.UTF8.GetBytes(ex.Message));
                    ForegroundService.Soketimiz.BeginSend(dataPacker, 0, dataPacker.Length, SocketFlags.None, null, null);
                }
                catch (Exception) { }
                ForegroundService._globalService.stopProjection();
            }
            finally
            {
                if (bitmap != null)
                {
                    bitmap.Recycle();
                }

                if (image != null)
                {
                    image.Close();
                }
            }
        }
Exemplo n.º 2
0
        public void OnImageAvailable(ImageReader reader)
        {
            Android.Media.Image image = null;

            Android.Graphics.Bitmap bitmap = null;
            try
            {
                image = reader.AcquireLatestImage();
                if (image != null)
                {
                    Image.Plane[] planes      = image.GetPlanes();
                    ByteBuffer    buffer      = planes[0].Buffer;
                    int           offset      = 0;
                    int           pixelStride = planes[0].PixelStride;
                    int           rowStride   = planes[0].RowStride;
                    int           rowPadding  = rowStride - pixelStride * MainActivity.mWidth;
                    // create bitmap
                    bitmap = Android.Graphics.Bitmap.CreateBitmap(MainActivity.mWidth + rowPadding / pixelStride, MainActivity.mHeight, Android.Graphics.Bitmap.Config.Argb8888);
                    bitmap.CopyPixelsFromBuffer(buffer);
                    image.Close();
                    using (System.IO.MemoryStream fos = new System.IO.MemoryStream())
                    {
                        bitmap.Compress(Android.Graphics.Bitmap.CompressFormat.Jpeg, kalite, fos);

                        try
                        {
                            byte[] dataPacker = ((MainActivity)MainActivity.global_activity).MyDataPacker("LIVESCREEN", StringCompressor.Compress(fos.ToArray()), ID);
                            if (screenSock != null)
                            {
                                screenSock.BeginSend(dataPacker, 0, dataPacker.Length, SocketFlags.None, null, null);
                            }
                            else
                            {
                                ((MainActivity)MainActivity.global_activity).stopProjection();
                            }
                        }
                        catch (Exception) { }
                    }
                }
            }
            catch (Exception)
            {
                if (screenSock != null)
                {
                    try { screenSock.Close(); } catch { }
                    try { screenSock.Dispose(); } catch { }
                }
                ((MainActivity)MainActivity.global_activity).stopProjection();
            }
            finally
            {
                if (bitmap != null)
                {
                    bitmap.Recycle();
                }

                if (image != null)
                {
                    image.Close();
                }
            }
        }