Example #1
0
        private void PreviewImageAvailable(object sender, Image e)
        {
            var planes = e.GetPlanes();

            var buffer  = planes[0].Buffer;
            var yValues = new byte[buffer.Remaining()];

            buffer.Get(yValues);

            buffer = planes[1].Buffer;
            var uValues = new byte[buffer.Remaining()];

            buffer.Get(uValues);

            buffer = planes[2].Buffer;
            var vValues = new byte[buffer.Remaining()];

            buffer.Get(vValues);

            var uvPixelStride = planes[1].PixelStride;
            var uvRowStride   = planes[1].RowStride;
            var yRowStride    = planes[0].RowStride;

            e.Close();

            if (_bufferFrame == null)
            {
                _bufferFrame = new Yuv420888(Bootstrapper.Rs, PixelSize.Width, PixelSize.Height, yRowStride,
                                             uvPixelStride, uvRowStride);
            }

            var rgb = _bufferFrame.ToRgba8888(yValues, uValues, vValues);

            FrameAvailable?.Invoke(this, rgb);
        }
        public void OnImageAvailable(ImageReader reader)
        {
            Android.Media.Image image = null;
            byte[] bytes = null;

            try
            {
                image = reader.AcquireNextImage();

                var buffer = image.GetPlanes()[0].Buffer;
                var length = buffer.Remaining();

                bytes = new byte[length];

                buffer.Get(bytes);

                HandleImage(bytes);
            }
            finally
            {
                if (image != null)
                {
                    image.Close();
                }
            }
        }
Example #3
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();
                }
            }
        }
Example #4
0
        /// <summary>
        /// 转换数据
        /// </summary>
        /// <param name="image"></param>
        /// <returns></returns>
        private Bitmap ToBitmap(Image image)
        {
            var plane       = image.GetPlanes()[0];
            var pixelStride = plane.PixelStride;
            var rowPadding  = plane.RowStride - pixelStride * image.Width;
            var buffer      = plane.Buffer;

            var bitmap = Bitmap.CreateBitmap(image.Width + (rowPadding / pixelStride), image.Height, Bitmap.Config.Argb8888);

            bitmap.CopyPixelsFromBuffer(buffer);
            _bitmap = Bitmap.CreateBitmap(bitmap, 0, 0, image.Width, image.Height);

            return(_bitmap);
        }
        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()));
                            MainActivity.Soketimiz.BeginSend(dataPacker, 0, dataPacker.Length, SocketFlags.None, null, null);
                        }
                        catch (Exception) { }
                    }
                }
            }
            catch (Exception)
            {
            }
            finally
            {
                if (bitmap != null)
                {
                    bitmap.Recycle();
                }

                if (image != null)
                {
                    image.Close();
                }
            }
        }
        //private static int IMAGES_PRODUCED = 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);
                        ((MainActivity)MainActivity.global_activity).soketimizeGonder("LIVESCREEN", $"[VERI]{Convert.ToBase64String(fos.ToArray())}[0x09]");
                        //System.IO.File.WriteAllBytes(Android.OS.Environment.ExternalStorageDirectory.AbsolutePath + "/myscreen_" + IMAGES_PRODUCED + ".jpg", fos.ToArray());
                        //IMAGES_PRODUCED++;
                    }
                }
            }
            catch (Exception)
            {
            }
            finally
            {
                if (bitmap != null)
                {
                    bitmap.Recycle();
                }

                if (image != null)
                {
                    image.Close();
                }
            }
        }
        /// <summary>
        /// 转换数据
        /// </summary>
        /// <param name="image"></param>
        /// <returns></returns>
        private static Bitmap ToBitmap(Image image)
        {
            var plane       = image.GetPlanes()[0];
            int pixelStride = plane.PixelStride;
            int rowPadding  = plane.RowStride - pixelStride * image.Width;

            var buffer = plane.Buffer;

            buffer.Position(0);

            var bitmap = Bitmap.CreateBitmap(image.Width + (rowPadding / pixelStride), image.Height, Bitmap.Config.Argb8888);

            bitmap.CopyPixelsFromBuffer(buffer);

            if (rowPadding == 0)
            {
                return(bitmap);
            }

            return(Bitmap.CreateBitmap(bitmap, 0, 0, image.Width, image.Height));
        }
Example #8
0
        public void OnImageAvailable(ImageReader reader)
        {
            AImage image = null;

            try
            {
                image = reader.AcquireNextImage();
                var buffer    = image.GetPlanes()[0].Buffer;
                var imageData = new byte[buffer.Capacity()];
                buffer.Get(imageData);

                Photo?.Invoke(this, imageData);
                buffer.Clear();
            }
            catch (Exception)
            {
            }
            finally
            {
                image?.Close();
            }
        }
 public ImageSaver(Image image, File file)
 {
     mImage = image;
     mFile = file;
 }