Beispiel #1
0
        public Texture(Context context, string fileName)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                return;
            }
            GLES20.GlGenTextures(1, textureHandle, 0); //init 1 texture storage handle
            if (textureHandle[0] != 0)
            {
                //Android.Graphics cose class Matrix exists at both Android.Graphics and Android.OpenGL and this is only sample of using
                Android.Graphics.BitmapFactory.Options options = new Android.Graphics.BitmapFactory.Options();
                options.InScaled = false; // No pre-scaling
                int id = context.Resources.GetIdentifier(fileName, "drawable", context.PackageName);
                Android.Graphics.Bitmap bitmap = Android.Graphics.BitmapFactory.DecodeResource(context.Resources, id, options);
                GLES20.GlBindTexture(GLES20.GlTexture2d, textureHandle[0]);
                GLES20.GlTexParameteri(GLES20.GlTexture2d, GLES20.GlTextureMinFilter, GLES20.GlNearest);
                GLES20.GlTexParameteri(GLES20.GlTexture2d, GLES20.GlTextureMagFilter, GLES20.GlNearest);
                GLES20.GlTexParameteri(GLES20.GlTexture2d, GLES20.GlTextureWrapS, GLES20.GlClampToEdge);
                GLES20.GlTexParameteri(GLES20.GlTexture2d, GLES20.GlTextureWrapT, GLES20.GlClampToEdge);
                GLUtils.TexImage2D(GLES20.GlTexture2d, 0, bitmap, 0);
                bitmap.Recycle();

                handle = textureHandle[0];
            }
        }
Beispiel #2
0
        public PwCustomIcon(PwUuid pwUuid, byte[] pbImageDataPng)
        {
            Debug.Assert(pwUuid != null);
            if (pwUuid == null)
            {
                throw new ArgumentNullException("pwUuid");
            }
            Debug.Assert(!pwUuid.Equals(PwUuid.Zero));
            if (pwUuid.Equals(PwUuid.Zero))
            {
                throw new ArgumentException("pwUuid == 0");
            }

            Debug.Assert(pbImageDataPng != null);
            if (pbImageDataPng == null)
            {
                throw new ArgumentNullException("pbImageDataPng");
            }

            m_pwUuid         = pwUuid;
            m_pbImageDataPng = pbImageDataPng;

#if !KeePassLibSD
            // MemoryStream ms = new MemoryStream(m_pbImageDataPng, false);
            // m_pCachedImage = Image.FromStream(ms);
            // ms.Close();
            m_pCachedImage = GfxUtil.LoadImage(m_pbImageDataPng);
#else
            m_pCachedImage = null;
#endif
        }
Beispiel #3
0
        public Bitmap ToBitmap(Bitmap.Config config)
        {
            System.Drawing.Size size = Size;

            if (config == Bitmap.Config.Argb8888)
            {
                Bitmap result = Bitmap.CreateBitmap(size.Width, size.Height, Bitmap.Config.Argb8888);

                using (BitmapArgb8888Image bi = new BitmapArgb8888Image(result))
                    using (Image <Rgba, Byte> tmp = ToImage <Rgba, Byte>())
                    {
                        tmp.Copy(bi, null);
                    }
                return(result);
            }
            else if (config == Bitmap.Config.Rgb565)
            {
                Bitmap result = Bitmap.CreateBitmap(size.Width, size.Height, Bitmap.Config.Rgb565);

                using (BitmapRgb565Image bi = new BitmapRgb565Image(result))
                    using (Image <Bgr, Byte> tmp = ToImage <Bgr, Byte>())
                        bi.ConvertFrom(tmp);
                return(result);
            }
            else
            {
                throw new NotImplementedException("Only Bitmap config of Argb888 or Rgb565 is supported.");
            }
        }
        //Create the remove red button
        private void NoRed(object sender, System.EventArgs e)
        {
            ImageView imageView = FindViewById <ImageView>(Resource.Id.takenPictureImageView);
            int       height    = Resources.DisplayMetrics.HeightPixels;
            int       width     = imageView.Height;

            Android.Graphics.Bitmap bitmap     = _file.Path.LoadAndResizeBitmap(width, height);
            Android.Graphics.Bitmap copyBitmap = bitmap.Copy(Android.Graphics.Bitmap.Config.Argb8888, true);
            for (int i = 0; i < copyBitmap.Width; i++)
            {
                for (int j = 0; j < copyBitmap.Height; j++)
                {
                    int p = copyBitmap.GetPixel(i, j);
                    //00000000 00000000 00000000 00000000
                    //long mask = (long)0xFF00FFFF;
                    //p = p & (int)mask;
                    Android.Graphics.Color c = new Android.Graphics.Color(p);
                    c.R = 0;
                    copyBitmap.SetPixel(i, j, c);
                }
            }
            if (bitmap != null)
            {
                imageView.SetImageBitmap(copyBitmap);
                imageView.Visibility = Android.Views.ViewStates.Visible;
            }

            System.GC.Collect();
        }
Beispiel #5
0
        public override void OnPageStarted(WebView view, string url, Android.Graphics.Bitmap favicon)
        {
            base.OnPageStarted(view, url, favicon);

            _urlText.Text = url;
            _urlText.SetSelection(0);
        }
Beispiel #6
0
        Android.Graphics.Color GetCurrentColor(Android.Graphics.Bitmap bitmap, int x, int y)
        {
            if (bitmap == null)
            {
                return(new Android.Graphics.Color(255, 255, 255, 255));
            }

            if (x < 0)
            {
                x = 0;
            }
            if (y < 0)
            {
                y = 0;
            }
            if (x >= bitmap.Width)
            {
                x = bitmap.Width - 1;
            }
            if (y >= bitmap.Height)
            {
                y = bitmap.Height - 1;
            }

            int color = bitmap.GetPixel(x, y);

            return(new Android.Graphics.Color(color));
        }
Beispiel #7
0
 //Adapted from: https://stackoverflow.com/questions/3012287/how-to-read-mms-data-in-android
 private Android.Graphics.Bitmap GetMmsImage(string _id)
 {
     Android.Net.Uri         mmsTextUri  = Android.Net.Uri.Parse("content://mms/part/" + _id);
     System.IO.Stream        inputStream = null;
     Android.Graphics.Bitmap bitmap      = null;
     try
     {
         ContentResolver contentResolver = AndroidApp.Context.ContentResolver;
         inputStream = contentResolver.OpenInputStream(mmsTextUri);
         bitmap      = Android.Graphics.BitmapFactory.DecodeStream(inputStream);
     }
     catch (System.IO.IOException error)
     {
         Log.Error(TAG, "Error reading MMS picture: " + error);
     }
     finally
     {
         if (inputStream != null)
         {
             try
             {
                 inputStream.Close();
             }
             catch (System.IO.IOException error)
             {
                 Log.Error(TAG, "Error closing input stream for reading MMS picture: " + error);
             }
         }
     }
     return(bitmap);
 }
        // <summary>
        // Called automatically whenever an activity finishes
        // </summary>
        // <param name = "requestCode" ></ param >
        // < param name="resultCode"></param>
        /// <param name="data"></param>
        protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);

            //Make image available in the gallery
            Intent mediaScanIntent = new Intent(Intent.ActionMediaScannerScanFile);
            var    contentUri      = Android.Net.Uri.FromFile(_file);

            mediaScanIntent.SetData(contentUri);
            SendBroadcast(mediaScanIntent);


            // Display in ImageView. We will resize the bitmap to fit the display.
            // Loading the full sized image will consume too much memory
            // and cause the application to crash.
            ImageView imageView = FindViewById <ImageView>(Resource.Id.takenPictureImageView);
            int       height    = Resources.DisplayMetrics.HeightPixels;
            int       width     = imageView.Height;

            Android.Graphics.Bitmap bitmap = _file.Path.LoadAndResizeBitmap(width, height);

            if (bitmap != null)
            {
                imageView.SetImageBitmap(bitmap);
                imageView.Visibility = Android.Views.ViewStates.Visible;
            }

            // Dispose of the Java side bitmap.
            System.GC.Collect();
        }
Beispiel #9
0
        public override bool OnCreateThumbnail(Android.Graphics.Bitmap outBitmap, Android.Graphics.Canvas canvas)
        {
            // ライフサイクルメソッド調査
            Util.Trace.WriteMethod();

            return(base.OnCreateThumbnail(outBitmap, canvas));
        }
        private void HighContrast(ImageView imageoutput)
        {
            Android.Graphics.Drawables.BitmapDrawable bd = (Android.Graphics.Drawables.BitmapDrawable)imageoutput.Drawable;
            Android.Graphics.Bitmap bitmap = bd.Bitmap;

            if (bitmap != null)
            {
                Android.Graphics.Bitmap copyBitmap = bitmap.Copy(Android.Graphics.Bitmap.Config.Argb8888, true);
                for (int i = 0; i < bitmap.Width; i++)
                {
                    for (int j = 0; j < bitmap.Height; j++)
                    {
                        int p = bitmap.GetPixel(i, j);
                        Android.Graphics.Color c = new Android.Graphics.Color(p);

                        c.R = (byte)(ContrastPixelValue(c.R));
                        c.G = (byte)(ContrastPixelValue(c.G));
                        c.B = (byte)(ContrastPixelValue(c.B));

                        copyBitmap.SetPixel(i, j, c);
                    }
                }
                if (copyBitmap != null)
                {
                    imageoutput.SetImageBitmap(copyBitmap);
                    bitmap     = null;
                    copyBitmap = null;
                }
                System.GC.Collect();
            }
        }
Beispiel #11
0
        /// <summary>
        /// Create a Mat from an Android Bitmap
        /// </summary>
        /// <param name="bitmap">The android Bitmap</param>
        public static Mat ToMat(this Android.Graphics.Bitmap bitmap)
        {
            Mat m = new Mat();

            bitmap.ToMat(m);
            return(m);
        }
Beispiel #12
0
 /// <summary>
 /// Convert a Bitmap to a Mat
 /// </summary>
 /// <param name="mat">The mat to copy Bitmap into</param>
 /// <param name="bitmap">The bitmap to copy into mat</param>
 public static void ToMat(this Android.Graphics.Bitmap bitmap, Mat mat)
 {
     Android.Graphics.Bitmap.Config config = bitmap.GetConfig();
     if (config.Equals(Android.Graphics.Bitmap.Config.Argb8888))
     {
         using (BitmapArgb8888Image bi = new BitmapArgb8888Image(bitmap))
         {
             CvInvoke.CvtColor(bi, mat, ColorConversion.Rgba2Bgra);
         }
     }
     else if (config.Equals(Android.Graphics.Bitmap.Config.Rgb565))
     {
         Size  size   = new Size(bitmap.Width, bitmap.Height);
         int[] values = new int[size.Width * size.Height];
         bitmap.GetPixels(values, 0, size.Width, 0, 0, size.Width, size.Height);
         GCHandle handle = GCHandle.Alloc(values, GCHandleType.Pinned);
         using (Mat bgra = new Mat(size, DepthType.Cv8U, 4, handle.AddrOfPinnedObject(), size.Width * 4))
         {
             bgra.CopyTo(mat);
         }
         handle.Free();
     }
     else
     {
         throw new NotImplementedException(String.Format("Coping from Bitmap of {0} is not implemented", config));
     }
 }
Beispiel #13
0
            public override void OnPageStarted(WebView view, string url, Android.Graphics.Bitmap favicon)
            {
                var uri = new Uri(url);

                activity.state.Authenticator.OnPageLoading(uri);
                activity.BeginProgress(uri.Authority);
            }
 public virtual Com.Zhy.Adapter.Abslistview.ViewHolder SetImageBitmap(int viewId,
                                                                      Android.Graphics.Bitmap bitmap)
 {
     Android.Widget.ImageView view = GetView <ImageView>(viewId);
     view.SetImageBitmap(bitmap);
     return(this);
 }
Beispiel #15
0
        public static Android.Graphics.Bitmap Rotate(Android.Graphics.Bitmap bitmap, int angle)
        {
            var mat = new Android.Graphics.Matrix();

            mat.PostRotate(angle);
            return(Android.Graphics.Bitmap.CreateBitmap(bitmap, 0, 0, bitmap.Width, bitmap.Height, mat, true));
        }
Beispiel #16
0
 public RadioStationNowPlaying(RadioStationSchedule.Slot slot, DateTimeOffset start, TimeSpan duration, Android.Graphics.Bitmap cover)
 {
     Slot     = slot;
     _start   = start;
     Duration = duration;
     Cover    = cover;
 }
Beispiel #17
0
        protected async override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Create your application here
            SetContentView(Resource.Layout.image_detail_activity);

            toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.imageToolBar);
            SetSupportActionBar(toolbar);
            SupportActionBar.SetDisplayHomeAsUpEnabled(true);
            SupportActionBar.SetDisplayShowHomeEnabled(true);

            imageView            = FindViewById <ImageViewTouch>(Resource.Id.myImageDetailView);
            imageView.LongClick += ImageView_LongClick;
            holdToShareTextView  = FindViewById <TextView>(Resource.Id.holdToShare);

            retrievedFilePath = (string)Intent.Extras.Get("filePath");
            try
            {
                Glide.With(this)
                .Load(Android.Net.Uri.FromFile(new Java.IO.File(retrievedFilePath)))
                .SetDiskCacheStrategy(DiskCacheStrategy.All)
                .Into(imageView);

                original = await Android.Graphics.BitmapFactory.DecodeFileAsync(retrievedFilePath);

                SupportActionBar.Title    = $"{retrievedFilePath.GetFileNameWithoutExtension()}";
                SupportActionBar.Subtitle = $"{original.Width} x {original.Height} | {PathHelper.GetFileLength(retrievedFilePath)} Kb";
            }
            catch
            {
                imageView.ContentDescription = "An error occured.";
            }
        }
Beispiel #18
0
 public void OnLoadingComplete(string p0, Android.Views.View p1, Bitmap bitmap)
 {
     if (!_source.Task.IsCanceled)
     {
         _source.TrySetResult(bitmap);
     }
 }
Beispiel #19
0
            public override void OnPageStarted(WebView view, string url, Android.Graphics.Bitmap favicon)
            {
                base.OnPageStarted(view, url, favicon);

                view.Visibility   = ViewStates.Gone;
                loader.Visibility = ViewStates.Visible;
            }
Beispiel #20
0
        public bool SendImage(Android.Graphics.Bitmap bitmap, WXScene scene = 0)
        {
            if (bitmap == null)
            {
                throw new Exception("(Android.Graphics.Bitmap) bitmap is null");
            }

            WXImageObject imgObj = new WXImageObject(bitmap);

            WXMediaMessage wxMediaMessage = new WXMediaMessage();

            wxMediaMessage.MyMediaObject = imgObj;

            // 设置缩略图
            int thumbSize = 150;                                                                 // 150是根据官网demo设置

            Android.Graphics.Bitmap thumbBmp = bitmap.ScaledBitmap(thumbSize, thumbSize, false); // 扩展方法
            bitmap.Recycle();

            wxMediaMessage.ThumbData = thumbBmp.ToArray(true); // 扩展方法

            //构造一个Req请求
            SendMessageToWX.Req req = new SendMessageToWX.Req();

            //唯一的请求标志
            req.Transaction = System.Guid.NewGuid().ToString();
            req.Message     = wxMediaMessage;

            // req.Scene = SendMessageToWX.Req.WXSceneSession; // 发送信息
            // req.Scene = SendMessageToWX.Req.WXSceneTimeline; // 发送朋友圈
            req.Scene = (int)scene;

            //发送数据
            return(api.SendReq(req));
        }
        /// <summary>
        /// Resize image bitmap
        /// </summary>
        /// <param name="photoPath"></param>
        /// <param name="newPhotoPath"></param>
        public void ResizeBitmaps(string photoPath, string newPhotoPath)
        {
            Android.Graphics.BitmapFactory.Options options = new Android.Graphics.BitmapFactory.Options();
            options.InPreferredConfig = Android.Graphics.Bitmap.Config.Argb8888;
            Android.Graphics.Bitmap bitmap        = Android.Graphics.BitmapFactory.DecodeFile(photoPath, options);
            Android.Graphics.Bitmap croppedBitmap = null;

            if (bitmap.Width >= bitmap.Height)
            {
                croppedBitmap = Android.Graphics.Bitmap.CreateBitmap(
                    bitmap,
                    bitmap.Width / 2 - bitmap.Height / 2,
                    0,
                    bitmap.Height,
                    bitmap.Height);
            }
            else
            {
                croppedBitmap = Android.Graphics.Bitmap.CreateBitmap(
                    bitmap,
                    0,
                    bitmap.Height / 2 - bitmap.Width / 2,
                    bitmap.Width,
                    bitmap.Width);
            }

            System.IO.FileStream stream = null;

            try
            {
                stream = new System.IO.FileStream(newPhotoPath, System.IO.FileMode.Create);
                croppedBitmap.Compress(Android.Graphics.Bitmap.CompressFormat.Png, 100, stream);
            }
            catch
            {
                //System.Diagnostics.Debug.WriteLineIf(App.Debugging, "Failed to close: " + ex.ToString());
            }
            finally
            {
                try
                {
                    if (stream != null)
                    {
                        stream.Close();
                    }

                    croppedBitmap.Recycle();
                    croppedBitmap.Dispose();
                    croppedBitmap = null;

                    bitmap.Recycle();
                    bitmap.Dispose();
                    bitmap = null;
                }
                catch
                {
                    //Debug.WriteLineIf(App.Debugging, "Failed to close: " + ex.ToString());
                }
            }
        }
        public async Task <string> Save(string filePath, string outputFolder, ImageFileType type)
        {
            var opts = new Android.Graphics.BitmapFactory.Options();

            opts.InPreferredConfig = Android.Graphics.Bitmap.Config.Argb8888;
            Android.Graphics.Bitmap bitmap = await Android.Graphics.BitmapFactory.DecodeFileAsync(filePath, opts);

            var outputpath = Path.Combine(outputFolder, Path.ChangeExtension(Path.GetFileName(filePath), type.ToString()));
            var stream     = new FileStream(outputpath, FileMode.Create);

            switch (type)
            {
            case ImageFileType.PNG:
                bitmap.Compress(Android.Graphics.Bitmap.CompressFormat.Png, 100, stream);
                break;

            case ImageFileType.JPG:
                bitmap.Compress(Android.Graphics.Bitmap.CompressFormat.Jpeg, 100, stream);
                break;

            default:
                throw new NotImplementedException();
            }
            stream.Close();

            return(outputpath);
        }
Beispiel #23
0
        //Negativ
        private Android.Graphics.Bitmap createInverse(Android.Graphics.Bitmap src)
        {
            float[] colorMatrix_Negative =
            {
                -1.0f,     0,     0,    0, 255,          //red
                0,     -1.0f,     0,    0, 255,          //green
                0,         0, -1.0f,    0, 255,          //blue
                0,         0,     0, 1.0f, 0             //alpha
            };

            Android.Graphics.Paint       MyPaint_Normal       = new Android.Graphics.Paint();
            Android.Graphics.Paint       MyPaint_Negative     = new Android.Graphics.Paint();
            Android.Graphics.ColorFilter colorFilter_Negative = new Android.Graphics.ColorMatrixColorFilter(colorMatrix_Negative);
            MyPaint_Negative.SetColorFilter(colorFilter_Negative);

            Android.Graphics.Bitmap bitmap = Android.Graphics.Bitmap.CreateBitmap(src.Width, src.Height,
                                                                                  Android.Graphics.Bitmap.Config.Argb8888);
            Android.Graphics.Canvas canvas = new Android.Graphics.Canvas(bitmap);

            MyPaint_Negative.SetColorFilter(colorFilter_Negative);
            canvas.DrawBitmap(src, 0, 0, MyPaint_Negative);

            return(bitmap);

            return(bitmap);
        }
Beispiel #24
0
 protected override void SetImageBitmapInto(Bitmap p0, View p1)
 {
     if (!_ct.IsCancellationRequested)
     {
         base.SetImageBitmapInto(p0, p1);
     }
 }
Beispiel #25
0
        // <summary>
        // Called automatically whenever an activity finishes
        // </summary>
        // <param name = "requestCode" ></ param >
        // < param name="resultCode"></param>
        /// <param name="data"></param>
        protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);

            //Make image available in the gallery

            /*
             * Intent mediaScanIntent = new Intent(Intent.ActionMediaScannerScanFile);
             * var contentUri = Android.Net.Uri.FromFile(_file);
             * mediaScanIntent.SetData(contentUri);
             * SendBroadcast(mediaScanIntent);
             */

            // Display in ImageView. We will resize the bitmap to fit the display.
            // Loading the full sized image will consume too much memory
            // and cause the application to crash.
            imageView = FindViewById <ImageView>(Resource.Id.takenPictureImageView);
            int height = Resources.DisplayMetrics.HeightPixels;
            int width  = imageView.Height;

            bitmap     = (Android.Graphics.Bitmap)data.Extras.Get("data");
            copyBitmap = bitmap.Copy(Android.Graphics.Bitmap.Config.Argb8888, true);
            ReplaceDisplay();

            // Build our gridview, and assign functions to each button
            var gridView = FindViewById <GridView>(Resource.Id.gridView);

            gridView.Adapter    = new ImageAdapter(this);
            gridView.ItemClick += GridView_ItemClick;

            // Dispose of the Java side bitmap.
            System.GC.Collect();
        }
        void Decode(Android.Graphics.Bitmap image)
        {
            try
            {
                var reader = new BarcodeReader();
                reader.Options.PossibleFormats = new List <BarcodeFormat>()
                {
                    CurrentFormat
                };
                reader.Options.TryHarder = true;
                var result = reader.Decode(image);
                if (result != null)
                {
                    var barcodescan = result.Text;

                    string[] barcodesections = barcodescan.Split('|');

                    this.textViewResults.Text = "Result: " + result.Text + System.Environment.NewLine + "Separated:" + System.Environment.NewLine + "ERP  / Model Number: " + barcodesections[0];
                }
                else
                {
                    this.textViewResults.Text = "No barcode found";
                    StartActivity(typeof(TypeSelectionActivity));
                }
            }
            catch (Exception ex)
            {
                this.textViewResults.Text = ex.ToString();
            }
        }
        /// <summary>
        /// Rotate the picture taken
        /// https://forums.xamarin.com/discussion/5409/photo-being-saved-in-landscape-not-portrait
        /// </summary>
        /// <param name="path"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <returns></returns>
        void RotateBitmap(string path, byte[] data)
        {
            try
            {
                //using (Android.Graphics.Bitmap picture = Android.Graphics.BitmapFactory.DecodeFile(path))
                using (Android.Graphics.Bitmap picture = data.ToBitmap())
                    using (Android.Graphics.Matrix mtx = new Android.Graphics.Matrix())
                    {
                        ExifInterface exif           = new ExifInterface(path);
                        string        orientation    = exif.GetAttribute(ExifInterface.TagOrientation);
                        var           camOrientation = int.Parse(orientation);

                        switch (_imageRotation)
                        {
                        case 0: // landscape
                            break;

                        case 90: // landscape upside down
                            mtx.PreRotate(270);
                            break;

                        case 180: // portrait
                            mtx.PreRotate(180);
                            break;

                        case 270: // portrait upside down
                            mtx.PreRotate(90);
                            break;
                        }

                        var    maxSize = 1024;
                        double w       = picture.Width;
                        double h       = picture.Height;
                        if (picture.Width > maxSize || picture.Height > maxSize)
                        {
                            // set scaled width and height to prevent out of memory exception
                            double scaleFactor = (double)maxSize / (double)picture.Width;
                            if (picture.Height > picture.Width)
                            {
                                scaleFactor = (double)maxSize / picture.Height;
                            }

                            w = picture.Width * scaleFactor;
                            h = picture.Height * scaleFactor;
                        }

                        using (var scaledPiture = Android.Graphics.Bitmap.CreateScaledBitmap(picture, (int)w, (int)h, false))
                            using (var rotatedPiture = Android.Graphics.Bitmap.CreateBitmap(scaledPiture, 0, 0, (int)w, (int)h, mtx, false))
                            {
                                SaveFile(path, rotatedPiture.ToBytes());
                            }
                    }
            }
            catch (Java.Lang.OutOfMemoryError e)
            {
                e.PrintStackTrace();
                throw;
            }
        }
Beispiel #28
0
        private void NListView_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
        {
            if (nAdapter[e.Position] == "@drawable/")
            {
                gimg_view.SetImageResource(this.Resources.GetIdentifier(nAdapter[e.Position], "drawable", this.PackageName));
            }

            switch (nAdapter[e.Position])
            {
            case "@drawable/gray":
            {
                temp_bit = toGrayscale(bitmap_img);
                gimg_view.SetImageBitmap(temp_bit);
                break;
            }

            case "@drawable/sepia":
            {
                temp_bit = createSepia_and_RBG(bitmap_img, 1);
                gimg_view.SetImageBitmap(temp_bit);
                break;
            }

            case "@drawable/blue":
            {
                temp_bit = createSepia_and_RBG(bitmap_img, 2);
                gimg_view.SetImageBitmap(temp_bit);
                break;
            }

            case "@drawable/red":
            {
                temp_bit = createSepia_and_RBG(bitmap_img, 4);
                gimg_view.SetImageBitmap(temp_bit);
                break;
            }

            case "@drawable/green":
            {
                temp_bit = createSepia_and_RBG(bitmap_img, 3);
                gimg_view.SetImageBitmap(temp_bit);
                break;
            }

            case "@drawable/negative":
            {
                temp_bit = createInverse(bitmap_img);
                gimg_view.SetImageBitmap(temp_bit);
                break;
            }

            case "@drawable/cancel":
            {
                temp_bit = bitmap_img;
                gimg_view.SetImageBitmap(bitmap_img);
                break;
            }
            }
        }
Beispiel #29
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();
                }
            }
        }
Beispiel #30
0
 public override void OnPageStarted(WebView view, string url, Android.Graphics.Bitmap favicon)
 {
     if (ProgChanged != null)
     {
         ProgChanged.Invoke(1);//on
     }
     base.OnPageStarted(view, url, favicon);
 }
Beispiel #31
0
      protected override void OnCreate(Bundle bundle)
      {
         base.OnCreate(bundle);

         this.SetContentView(Resource.Layout.EncoderActivityLayout);


         buttonGenerate = this.FindViewById<Button>(Resource.Id.buttonEncoderGenerate);
         buttonSaveToGallery = this.FindViewById<Button>(Resource.Id.buttonEncoderSaveBarcode);
         textValue = this.FindViewById<EditText>(Resource.Id.textEncoderValue);
         imageBarcode = this.FindViewById<ImageView>(Resource.Id.imageViewEncoderBarcode);
         textViewEncoderMsg = this.FindViewById<TextView>(Resource.Id.textViewEncoderMsg);

         this.buttonSaveToGallery.Enabled = false;
         this.Title = "Write: " + CurrentFormat.ToString();

         buttonGenerate.Click += (sender, e) =>
         {

            var value = string.Empty;

            this.RunOnUiThread(() => { value = this.textValue.Text; });

            try
            {
               var writer = new BarcodeWriter
                               {
                                  Format = CurrentFormat,
                                  Options = new EncodingOptions
                                               {
                                                  Height = 200,
                                                  Width = 600
                                               }
                               };
               bitmap = writer.Write(value);

               this.RunOnUiThread(() =>
               {
                  this.imageBarcode.SetImageDrawable(new Android.Graphics.Drawables.BitmapDrawable(bitmap));
                  this.buttonSaveToGallery.Enabled = true;
               });
            }
            catch (Exception ex)
            {
               bitmap = null;
               this.buttonSaveToGallery.Enabled = false;
               this.RunOnUiThread(() => this.textViewEncoderMsg.Text = ex.ToString());
            }
         };

         buttonSaveToGallery.Click += (sender, e) =>
         {
            Android.Provider.MediaStore.Images.Media.InsertImage(this.ContentResolver, bitmap, "Zxing.Net: " + CurrentFormat.ToString(), "");
         };
      }
Beispiel #32
0
 public void AddOrUpdate(string key, Bitmap bmp, TimeSpan duration)
 {
     key = SanitizeKey (key);
     lock (entries) {
         bool existed = entries.ContainsKey (key);
         using (var stream = new BufferedStream (File.OpenWrite (Path.Combine (basePath, key))))
             bmp.Compress (Bitmap.CompressFormat.Png, 100, stream);
         AppendToJournal (existed ? JournalOp.Modified : JournalOp.Created,
                          key,
                          DateTime.UtcNow,
                          duration);
         entries[key] = new CacheEntry (DateTime.UtcNow, duration);
     }
 }
Beispiel #33
0
        public PwCustomIcon(PwUuid pwUuid, byte[] pbImageDataPng)
        {
            Debug.Assert(pwUuid != null);
            if(pwUuid == null) throw new ArgumentNullException("pwUuid");
            Debug.Assert(!pwUuid.Equals(PwUuid.Zero));
            if(pwUuid.Equals(PwUuid.Zero)) throw new ArgumentException("pwUuid == 0");

            Debug.Assert(pbImageDataPng != null);
            if(pbImageDataPng == null) throw new ArgumentNullException("pbImageDataPng");

            m_pwUuid = pwUuid;
            m_pbImageDataPng = pbImageDataPng;

            #if !KeePassLibSD
            // MemoryStream ms = new MemoryStream(m_pbImageDataPng, false);
            // m_pCachedImage = Image.FromStream(ms);
            // ms.Close();
            m_pCachedImage = GfxUtil.LoadImage(m_pbImageDataPng);
            #else
            m_pCachedImage = null;
            #endif
        }
 public Bitmap(string filename)
 {
     ABitmap = Android.Graphics.BitmapFactory.DecodeFile (filename);
 }
        /// <summary>
        /// Take a picture and perform previews
        /// </summary>
        /// <param name="data"></param>
        /// <param name="camera"></param>
        void Camera.IPictureCallback.OnPictureTaken(byte[] data, Android.Hardware.Camera camera)
        {
			if (data != null && _box != null)
            {
				if (!_processDialog.IsShowing) {
					_processDialog.SetMessage ("Waiting for image results...");
					_processDialog.Show ();
				}
				Android.Graphics.BitmapFactory.Options options = new Android.Graphics.BitmapFactory.Options ();
				options.InJustDecodeBounds = true;
				options.InSampleSize = 2;
				options.InJustDecodeBounds = false;
				options.InTempStorage = new byte[16 * 1024];
                Android.Graphics.Bitmap bmp = Android.Graphics.BitmapFactory.DecodeByteArray(data, 0, data.Length, options);
                data = null;
				GC.Collect ();
                Android.Graphics.Bitmap rotatedBitmap;
                if (bmp.Width > bmp.Height)
                {
                    Android.Graphics.Matrix mtx = new Android.Graphics.Matrix();
                    mtx.SetRotate(90);
                    rotatedBitmap = Android.Graphics.Bitmap.CreateBitmap(bmp, 0, 0, bmp.Width, bmp.Height, mtx, false);
                    bmp.Recycle();
                    mtx.Dispose();
                    mtx = null;
                }
                else
                {
                    rotatedBitmap = bmp.Copy(bmp.GetConfig(), true);
                    bmp.Recycle();
                }
				GC.Collect ();
                double ratioX = (double)rotatedBitmap.Width / (double)screenWidth;
                double ratioY = (double)rotatedBitmap.Height / (double)screenHeight;
                int startX = (int)(ratioX * (double)(_box.MidX - _box.Width / 2));
                int startY = (int)(ratioY * (double)(_box.MidY - _box.Height / 2));
                int width = (int)(ratioX * (double)_box.Width);
                int height = (int)(ratioY * (double)_box.Height);
                Android.Graphics.Bitmap croppedBitmap = Android.Graphics.Bitmap.CreateBitmap(rotatedBitmap, startX, startY, width, height);
                rotatedBitmap.Recycle();
				GC.Collect ();
                bitmap = croppedBitmap.Copy(croppedBitmap.GetConfig(), true);
                PerformPreviews(croppedBitmap);
            }
            else
            {
                Toast.MakeText(this, "Data null error", ToastLength.Long).Show();
            }
        }
        protected override void OnStart()
        {
            base.OnStart();

            TesseractInit();
			button.Enabled = true;
            _boxPaint.Color = _boxWhite;
            _boxPaint.SetStyle(Android.Graphics.Paint.Style.Stroke);
            _boxPaint.StrokeWidth = 5;
            _backgroundPaint.Color = Android.Graphics.Color.Black;
            _backgroundPaint.Alpha = 255 / 2;
            _backgroundPaint.SetStyle(Android.Graphics.Paint.Style.Fill);
            _backgroundClearPaint.SetXfermode(new Android.Graphics.PorterDuffXfermode(Android.Graphics.PorterDuff.Mode.Clear));
            _resizePaint.Alpha = 255 / 2;
            _resizePaint.Color = _boxWhite;
            _resizePaint.SetStyle(Android.Graphics.Paint.Style.Fill);
            _resizePaint.StrokeWidth = 1;

            _surfaceCamera = (SurfaceView)FindViewById(Resource.Id.surfaceCamera);
            _holderCamera = _surfaceCamera.Holder;
            _holderCamera.AddCallback(this);

            _surfaceBox = (SurfaceView)FindViewById(Resource.Id.surfaceBox);
            _surfaceBox.SetOnTouchListener(this);
            _surfaceBox.SetWillNotDraw(false);
            _holderBox = _surfaceBox.Holder;
            _holderBox.AddCallback(this);
            _holderBox.SetFormat(Android.Graphics.Format.Transparent);
            _surfaceBox.SetZOrderOnTop(true);

            _boxThread = new Thread(new ThreadStart(() =>
            {
                long lastUpdate = 0;
                double fps = 60.0;
                while (_cameraActive)
                {
                    if (System.Environment.TickCount - lastUpdate > 1000 / fps)
                    {
                        lastUpdate = System.Environment.TickCount;
						if (_box != null) {
							DrawBox();
						}
                    }
                }
            }));
            bitmap = Android.Graphics.Bitmap.CreateBitmap(1, 1, Android.Graphics.Bitmap.Config.Argb8888);
			bitmapWithBoxes = Android.Graphics.Bitmap.CreateBitmap(1, 1, Android.Graphics.Bitmap.Config.Argb8888);
			for (int i = 0; i < threshholds.Length; i++)
            {
                threshholds[i] = 10 + i * 2;
            }
            _cameraActive = true;
            _toast = Toast.MakeText(this, "", ToastLength.Short);
            _processDialog = new Android.App.ProgressDialog(this);
            _processDialog.Indeterminate = true;
            _processDialog.SetProgressStyle(Android.App.ProgressDialogStyle.Spinner);
            _processDialog.SetTitle("Please wait");
            _processDialog.SetMessage("Please wait...");
            _processDialog.SetCancelable(true);
        }
Beispiel #37
0
 public override void Dispose()
 {
     if (ABitmap != null)
     {
         ABitmap.Dispose();
         ABitmap = null;
     }
 }
 public Bitmap(Android.Graphics.Bitmap backingBitmap)
 {
     _backingBitmap = backingBitmap;
 }
Beispiel #39
0
		public Bitmap (Android.Graphics.Bitmap androidBitmap)
		{
			ABitmap = androidBitmap;
		}
 public PictureTakenEventArgs(Android.Graphics.Bitmap bmp, Camera camera)
 {
    Bitmap = bmp;
    Camera = camera;
 }
Beispiel #41
0
 public Bitmap (int w, int h)
 {
     ABitmap = Android.Graphics.Bitmap.CreateBitmap (w, h, Android.Graphics.Bitmap.Config.Argb8888);
 }
Beispiel #42
0
        public bool TryGet(string key, out Bitmap bmp)
        {
            key = SanitizeKey (key);
            lock (entries) {
                bmp = null;
                if (!entries.ContainsKey (key))
                    return false;
                try {
                    bmp = Android.Graphics.BitmapFactory.DecodeFile (Path.Combine (basePath, key));
                } catch {
                    return false;
                }

                return true;
            }
        }
Beispiel #43
0
 void UpdateArt()
 {
     if(_currentAlbumArt != null)
     {
         _currentAlbumArt.Recycle();
         _currentAlbumArt.Dispose();
     }
     if(_model.AlbumArtStream != null)
     {
         Console.WriteLine ("Change Art");
         _currentAlbumArt = Android.Graphics.BitmapFactory.DecodeByteArray(_model.AlbumArtStream.ToArray(), 0, (int)_model.AlbumArtStream.Length);
         FindViewById<ImageView>(Resource.Id.imgPlayingAlbumArt).SetImageBitmap(_currentAlbumArt);
     }
 }
 public Bitmap(Stream rs)
 {
     ABitmap = Android.Graphics.BitmapFactory.DecodeStream(rs);
 }
Beispiel #45
0
 protected override void OnDestroy()
 {
     base.OnDestroy ();
     Console.WriteLine ("Activity Destroyed");
     ImageButton btn = FindViewById<ImageButton>(Resource.Id.imgPlayingNext);
     if(btn != null)
     {
         btn.Click -= HandleNextClick;
     }
     btn = FindViewById<ImageButton>(Resource.Id.imgPlayingPrevious);
     if(btn != null)
     {
         btn.Click -= HandlePreviousClick;
     }
     btn = FindViewById<ImageButton>(Resource.Id.imgPlayingPlayPause);
     if(btn != null)
     {
         btn.Click -= HandlePlayClick;
     }
     btn = FindViewById<ImageButton>(Resource.Id.imgPlayingShuffle);
     if(btn != null)
     {
         btn.Click -= HandleShuffleClick;
     }
     if (_currentAlbumArt != null)
     {
         _currentAlbumArt.Recycle ();
         _currentAlbumArt.Dispose ();
         _currentAlbumArt = null;
     }
     UnbindService(_connection);
     _connection.Dispose();
     _connection = null;
 }
      protected override void OnDraw(Android.Graphics.Canvas canvas)
      {
         base.OnDraw(canvas);

         lock (this)
         {
            Image<Bgr, byte> image = _bgrBuffers.GetBuffer(0);

            if (image != null && !_imageSize.IsEmpty && canvas != null)
            {
               Stopwatch w = Stopwatch.StartNew();

               if ((_bmpImage != null) && (!_imageSize.Equals(_bmpImage.Size)))
               {
                  _bmpImage.Dispose();
                  _bmpImage = null;
                  _bmp.Dispose();
                  _bmp = null;
               }

               if (_bmpImage == null)
               {
                  _bmp = Android.Graphics.Bitmap.CreateBitmap(_imageSize.Width, _imageSize.Height, Android.Graphics.Bitmap.Config.Rgb565);
                  _bmpImage = new BitmapRgb565Image(_bmp);
               }

               _bmpImage.ConvertFrom(image);

               canvas.DrawBitmap(_bmp, 0, 0, _paint);

               w.Stop();

               _watch.Stop();
               
#if DEBUG
               canvas.DrawText(String.Format("{0:F2} FPS; {1}x{2}; Render Time: {3} ms",
                  1.0 / _watch.ElapsedMilliseconds * 1000,
                  _imageSize.Width,
                  _imageSize.Height,
                  w.ElapsedMilliseconds), 20, 20, _paint);
#endif
               _watch.Reset();
               _watch.Start();
            }
         }
      }
 public Bitmap(MemoryStream ms)
 {
     ABitmap = Android.Graphics.BitmapFactory.DecodeStream(ms);
 }