示例#1
0
        AndroidNetUri GenerateRandomFileUrlInDemoTempStorage(string fileExtension)
        {
            var targetFile = System.IO.Path.Combine(
                MainApplication.TempImageStorage.TempDir, UUID.RandomUUID() + fileExtension);

            return(AndroidNetUri.FromFile(new Java.IO.File(targetFile)));
        }
        /// <summary>
        /// Create an intent to take a picture.
        /// </summary>
        public void TakeAPicture()
        {
            Intent intent = new Intent(MediaStore.ActionImageCapture);

            intent.PutExtra(MediaStore.ExtraOutput, Uri.FromFile(file));
            StartActivityForResult(intent, 0);
        }
示例#3
0
        private void GalleryImagePreview(string name)
        {
            switch (name)
            {
            case "":
                Toast.MakeText(context, "Please Wait while Image is being Synced", ToastLength.Short).Show();
                break;

            default:
            {
                String sdCardPath = Environment.ExternalStorageDirectory.AbsolutePath;
                String filePath   = Path.Combine(sdCardPath, "Checkd/" + name);

                File file = new File(filePath);
                if (file.Exists())
                {
                    Uri    pdfPath = Uri.FromFile(new File(filePath));
                    Intent intent  = new Intent(Intent.ActionView);
                    intent.SetDataAndType(pdfPath, "image/*");
                    intent.SetFlags(ActivityFlags.NewTask);
                    context.StartActivity(intent);
                }
                else
                {
                    Toast.MakeText(context, "There is no photo available to show", ToastLength.Short).Show();
                }
            }
            break;
            }
        }
        private void OpenImage(File file)
        {
            SetContentView(Resource.Layout.Display_Image_layout);
            var image = FindViewById <ImageView>(Resource.Id.imageView);

            image.SetImageURI(Uri.FromFile(file));
        }
        protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);

            // Make it available in the gallery

            Intent mediaScanIntent = new Intent(Intent.ActionMediaScannerScanFile);
            Uri    contentUri      = Uri.FromFile(App._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 to much memory
            // and cause the application to crash.

            int height = Resources.DisplayMetrics.HeightPixels;
            int width  = imgPhoto.Width;

            App.bitmap = App._file.Path.LoadAndResizeBitmap(width, height);
            if (App.bitmap != null)
            {
                var rotatedImage = RotateImage(App.bitmap, -90);
                imgPhoto.SetImageBitmap(rotatedImage);
                var base64 = BitmapHelpers.ConvertBitMapToBase64String(rotatedImage);
                commons.Instance.image = base64;
                App.bitmap             = null;
            }

            // Dispose of the Java side bitmap.
            GC.Collect();
        }