/// <summary>
		/// Try go get output file
		/// </summary>
		/// <param name="context"></param>
		/// <param name="subdir"></param>
		/// <param name="name"></param>
		/// <param name="isPhoto"></param>
		/// <param name="saveToAlbum"></param>
		/// <returns></returns>
        public static Uri GetOutputMediaFile(Context context, string subdir, string name, bool isPhoto, bool saveToAlbum)
        {
            subdir = subdir ?? string.Empty;

            if (string.IsNullOrWhiteSpace(name))
            {
                var timestamp = DateTime.Now.ToString("yyyyMMdd_HHmmss", CultureInfo.InvariantCulture);
                if (isPhoto)
                    name = "IMG_" + timestamp + ".jpg";
                else
                    name = "VID_" + timestamp + ".mp4";
            }

            var mediaType = (isPhoto) ? Environment.DirectoryPictures : Environment.DirectoryMovies;
            var directory = saveToAlbum ? Environment.GetExternalStoragePublicDirectory(mediaType) : context.GetExternalFilesDir(mediaType);
            using (var mediaStorageDir = new Java.IO.File(directory, subdir))
            {
                if (!mediaStorageDir.Exists())
                {
                    if (!mediaStorageDir.Mkdirs())
                        throw new IOException("Couldn't create directory, have you added the WRITE_EXTERNAL_STORAGE permission?");

                    if (!saveToAlbum)
                    {
                        // Ensure this media doesn't show up in gallery apps
                        using (var nomedia = new Java.IO.File(mediaStorageDir, ".nomedia"))
                            nomedia.CreateNewFile();
                    }
                }

                return Uri.FromFile(new Java.IO.File(GetUniquePath(mediaStorageDir.Path, name, isPhoto)));
            }
        }
Exemple #2
0
        private void TakePhoto(object sender, EventArgs e)
        {
            picDir = AEnvironment.GetExternalStoragePublicDirectory(AEnvironment.DirectoryPictures);
            bkDir  = new AFile(picDir, "Bookkeeper");
            if (!bkDir.Exists())
            {
                bkDir.Mkdirs();
            }
            int id;

            if (BookkeeperManager.Instance.GetEntries().Count > 0)
            {
                id = BookkeeperManager.Instance.GetEntries().Select(b => b.Id).Max() + 1;
            }
            else
            {
                id = 0;
            }

            photoFile = new AFile(bkDir, "entry" + id + ".jpg");
            photoUri  = AUri.FromFile(photoFile);

            Intent intent = new Intent(MediaStore.ActionImageCapture);

            intent.PutExtra(MediaStore.ExtraOutput, photoUri);
            StartActivityForResult(intent, 0);
        }
        public string GetDirectory()
        {
            //string documentsPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments); // Documents folder
            File picturesDirectory = Environment.GetExternalStoragePublicDirectory(Environment.DirectoryPictures);

            return(picturesDirectory.ToString());
        }
Exemple #4
0
        private string GetFilePath()
        {
            String path = Path.Combine(Environment.GetExternalStoragePublicDirectory(Environment.DirectoryDownloads).AbsolutePath,
                                       "jjj.pdf");

            return(path);
        }
Exemple #5
0
        /// <summary>
        /// Generate and save a screenshot.
        /// </summary>
        /// <param name="filename">The filename you'd like to use, with no path or file extension. Leave blank for the default filename</param>
        /// <param name="appendTimeStamp">Whether or not to append the current date/time to the end of the filename. </param>
        /// <returns>The full path, filename, and extension of the file that was created.</returns>
        public static string CreateFilename(string filename, string extension, bool appendTimeStamp = true)
        {
            //Setup the filename
            if (appendTimeStamp)
            {
                filename += $"_{DateTime.Now.ToFileTime()}";
            }

            //append the file extension
            filename += extension;

            //put the file in the Pictures folder. This assumes you have all the correct external storage permissions!!!
#if ANDROID
            var fullFilename = Environment.GetExternalStoragePublicDirectory(Environment.DirectoryPictures).AbsolutePath;
#else
            var fullFilename = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
#endif

            //create that directory if it doesn't exist
            if (!Directory.Exists(fullFilename))
            {
                Directory.CreateDirectory(fullFilename);
            }

            fullFilename = Path.Combine(fullFilename, filename);

            return(fullFilename);
        }
        //  From Github:
        //  https://github.com/xamurais/Xamarin.android/tree/master/CamaraFoto
        private Uri GetOutputMediaFile(string subdir, string name)
        {
            subdir = subdir ?? String.Empty;

            //  Name the pic
            if (String.IsNullOrWhiteSpace(name))
            {
                string timestamp = DateTime.Now.ToString("yyyyMMdd_HHmmss");
                name = "IMG_" + timestamp + ".jpg";
            }

            //  Get cellphone pictures directory
            string mediaType = Environment.DirectoryPictures;

            //  Get complete path
            using (Java.IO.File mediaStorageDir = new Java.IO.File(
                       Environment.GetExternalStoragePublicDirectory(mediaType), subdir))
            {
                //  If the directory doesn't exist, create it
                if (!mediaStorageDir.Exists())
                {
                    if (!mediaStorageDir.Mkdirs())
                    {
                        throw new IOException("No se pudo crear el directorio");
                    }
                }

                return(Uri.FromFile(new Java.IO.File(GetUniquePath(mediaStorageDir.Path, name))));
            }
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_main);

            _carRepository = new CarRepository();
            _options       = Resources.GetStringArray(Resource.Array.menu);
            Array.Sort(_options);

            textMessage = FindViewById <TextView>(Resource.Id.message);
            BottomNavigationView navigation = FindViewById <BottomNavigationView>(Resource.Id.navigation);

            navigation.SetOnNavigationItemSelectedListener(this);

            _dir = new Java.IO.File(
                Environment.GetExternalStoragePublicDirectory(
                    Environment.DirectoryPictures), "CameraAppTMP");
            if (!_dir.Exists())
            {
                _dir.Mkdirs();
            }

            var googl = new GoogleSynchronizer();
            var input = Assets.Open("credentials.json", Access.Streaming);

            _files = googl.Authorize(input, _dir.AbsolutePath);
            CreateViewForLastVin();
        }
Exemple #8
0
        public override string MediaFolderPath(MediaOptions mediaOptions)
        {
            string result;

            if (mediaOptions.UsePublicStorage == false)
            {
                result = Android.App.Application.Context.GetExternalFilesDir(null).AbsolutePath;
            }
            else
            {
                result = Env.GetExternalStoragePublicDirectory(Env.DirectoryPictures).AbsolutePath;
            }

            if (string.IsNullOrWhiteSpace(mediaOptions.Directory) == false)
            {
                result = System.IO.Path.Combine(result, mediaOptions.Directory);
            }

            if (Directory.Exists(result).Equals(false))
            {
                Directory.CreateDirectory(result);
            }

            return(result);
        }
        private void button_TakePhoto(object sender, EventArgs e)
        {
            AFile picDir      = AEnvironment.GetExternalStoragePublicDirectory(AEnvironment.DirectoryPictures);
            AFile receiptsDir = new AFile(picDir, "Bookkeeper");

            if (!receiptsDir.Exists())
            {
                receiptsDir.Mkdirs();
            }
            if ("new".Equals(activityType))
            {
                imagePath = "receiptId" + (bookKeeperManager.GetLastEntryId() + 1) + ".jpg";
            }
            else if ("update".Equals(activityType))
            {
                imagePath = "receiptId" + entry.Id + ".jpg";
            }

            AFile myFile = new AFile(receiptsDir, imagePath);

            imagePathUri = AUri.FromFile(myFile);
            Intent intent = new Intent(MediaStore.ActionImageCapture);

            intent.PutExtra(MediaStore.ExtraOutput, imagePathUri);
            StartActivityForResult(intent, CAMERA_REQUEST_CODE);
        }
Exemple #10
0
        //OBTENEMOS LA URI DE NUESTRA FUTURA IMAGEN
        Uri GetOutputMediaFile(Context context, string subdir, string name)
        {
            subdir = subdir ?? String.Empty;
            //SI NO SE LE ASIGNA UN NOMBRE DE IMAGEN, EL SISTEMA ASIGNA UNO
            if (String.IsNullOrWhiteSpace(name))
            {
                string timestamp = DateTime.Now.ToString("yyyyMMdd_HHmmss");
                name = "IMG_" + timestamp + ".jpg";
            }

            //OBTENEMOS EL PATH DONDE SE ENCUENTRA EL DIRECTORIO DE PICTURES DENTRO DE NUESTRO DISPOSITIVO
            string mediaType = Environment.DirectoryPictures;

            //OBTENEMOS EL PATH ABSOLUTO EN COMBINACION CON EL SUBDIRECTORIO DONDE GUARDAREMOS LAS IMAGENES
            using (Java.IO.File mediaStorageDir = new Java.IO.File(Environment.GetExternalStoragePublicDirectory(mediaType), subdir))
            {
                //VERIFICAMOS QUE EXISTA EL SUBDIRECTORIO
                if (!mediaStorageDir.Exists())
                {
                    //SI NO EXISTE CREAMOS EL DIRECTORIO
                    if (!mediaStorageDir.Mkdirs())
                    {
                        throw new IOException("NO se pudo crear el directorio, asegurece que tenga permisos la APP para crear archivos");
                    }
                }

                //REGRESAMOS LA URI DE LA NUEVA IMAGEN QUE SE USARA PARA GUARDAR LA FOTO
                return(Uri.FromFile(new Java.IO.File(GetUniquePath(mediaStorageDir.Path, name))));
            }
        }
Exemple #11
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            _carRepository = new CarRepository();
            _options       = Resources.GetStringArray(Resource.Array.menu);
            Array.Sort(_options);

            SetContentView(Resource.Layout.activity_main);
            Android.Support.V7.Widget.Toolbar toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
            SetSupportActionBar(toolbar);

            FloatingActionButton fab = FindViewById <FloatingActionButton>(Resource.Id.fab);

            fab.Click += FabOnClick;

            DrawerLayout          drawer = FindViewById <DrawerLayout>(Resource.Id.drawer_layout);
            ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, Resource.String.navigation_drawer_open, Resource.String.navigation_drawer_close);

            drawer.AddDrawerListener(toggle);
            toggle.SyncState();

            NavigationView navigationView = FindViewById <NavigationView>(Resource.Id.nav_view);

            navigationView.SetNavigationItemSelectedListener(this);

            _dir = new Java.IO.File(
                Environment.GetExternalStoragePublicDirectory(
                    Environment.DirectoryPictures), "CameraAppDemo");
            if (!_dir.Exists())
            {
                _dir.Mkdirs();
            }
        }
Exemple #12
0
 private void CreateDirectoryForPictures()
 {
     App._dir = new File(
         Environment.GetExternalStoragePublicDirectory(
             Environment.DirectoryPictures), "MathFighterPhotos");
     App._dir.Mkdirs();
 }
Exemple #13
0
        public void SubCrearJpgAforo(string lStrCuenca)
        {
            File lObjDirectorio = new File(Environment.GetExternalStoragePublicDirectory(Environment.DirectoryPictures), "ICC");

            if (!lObjDirectorio.Exists())
            {
                lObjDirectorio.Mkdirs();
            }
            File lObjArchivo            = new File(lObjDirectorio, string.Format("{0}{1}.jpg", lStrCuenca, cObjInicio.cTran.Codigo));
            View view                   = Window.DecorView;
            var  wasDrawingCacheEnabled = view.DrawingCacheEnabled;

            view.DrawingCacheEnabled = true;
            view.BuildDrawingCache(true);
            var lObjBitmap = Bitmap.CreateBitmap(view.GetDrawingCache(true));

            view.DrawingCacheEnabled = wasDrawingCacheEnabled;
            using (var lBjFileStream = new System.IO.FileStream(lObjArchivo.AbsolutePath, System.IO.FileMode.CreateNew))
            {
                lObjBitmap.Compress(Bitmap.CompressFormat.Jpeg, 95, lBjFileStream);
            }
            Uri.FromFile(lObjArchivo);
            Intent mediaScanIntent = new Intent(Intent.ActionMediaScannerScanFile);
            Uri    contentUri      = Uri.FromFile(lObjArchivo);

            mediaScanIntent.SetData(contentUri);
            SendBroadcast(mediaScanIntent);
        }
        public async Task <bool> SavePhotoAsync(byte[] data, string folder, string filename)
        {
            try
            {
                File picturesDirectory = Environment.GetExternalStoragePublicDirectory(Environment.DirectoryPictures);
                File folderDirectory   = picturesDirectory;

                if (!string.IsNullOrEmpty(folder))
                {
                    folderDirectory = new File(picturesDirectory, folder);
                    folderDirectory.Mkdirs();
                }

                using (File bitmapFile = new File(folderDirectory, filename))
                {
                    bitmapFile.CreateNewFile();

                    using (FileOutputStream outputStream = new FileOutputStream(bitmapFile))
                    {
                        await outputStream.WriteAsync(data);
                    }
                }
            }
            catch (Exception ex)
            {
                return(false);
            }

            return(true);
        }
Exemple #15
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            ViewGroup root = (ViewGroup)inflater.Inflate(Resource.Layout.aboutMeFragment, null);


            myPhoto = (ImageView)root.FindViewById(Resource.Id.imageView1);
            Button button = (Button)root.FindViewById(Resource.Id.myButton);

            //createDirectory();

            _file = null;
            _file = new Java.IO.File(Environment.GetExternalStoragePublicDirectory(Environment.DirectoryPictures), "avatar.png");
            if (_file.Exists())
            {
                myPhoto.SetImageURI(Uri.FromFile(_file));
            }

            button.Click += delegate
            {
                //SelectImage();
                ShowCamera();
            };

            return(root);
        }
Exemple #16
0
        // シャッターを切った時のコールバック
        public void OnPictureTaken(byte[] data, AndroidCamera camera)
        {
            try {
                var SaveDir = new Java.IO.File(Environment.GetExternalStoragePublicDirectory(Environment.DirectoryDcim), "Camera");
                if (!SaveDir.Exists())
                {
                    SaveDir.Mkdir();
                }


                // 非同期で画像の回転・保存・アルバムへの登録
                Task.Run(async() => {
                    // 保存ディレクトリに入ってるファイル数をカウント
                    var Files = SaveDir.List();
                    int count = 0;
                    foreach (var tmp in Files)
                    {
                        count++;
                    }

                    Matrix matrix = new Matrix();                       // 回転用の行列
                    matrix.SetRotate(90 - DetectScreenOrientation());
                    Bitmap original = BitmapFactory.DecodeByteArray(data, 0, data.Length);
                    Bitmap rotated  = Bitmap.CreateBitmap(original, 0, 0, original.Width, original.Height, matrix, true);

                    var FileName = new Java.IO.File(SaveDir, "DCIM_" + (count + 1) + ".jpg");


                    // ファイルをストレージに保存
                    FileStream stream = new FileStream(FileName.ToString(), FileMode.CreateNew);
                    await rotated.CompressAsync(Bitmap.CompressFormat.Jpeg, 90, stream);
                    stream.Close();

                    Android.Media.ExifInterface Exif = new ExifInterface(FileName.ToString());
                    Exif.SetAttribute(ExifInterface.TagGpsLatitude, Latitude);
                    Exif.SetAttribute(ExifInterface.TagGpsLongitude, Longitude);
                    Exif.SetAttribute(ExifInterface.TagGpsLatitudeRef, "N");
                    Exif.SetAttribute(ExifInterface.TagGpsLongitudeRef, "E");
                    Exif.SaveAttributes();


                    // 保存したファイルをアルバムに登録
                    string[] FilePath = { Environment.GetExternalStoragePublicDirectory(Environment.DirectoryDcim) + "/Camera/" + "DCIM_" + (count + 1) + ".jpg" };
                    string[] mimeType = { "image/jpeg" };
                    MediaScannerConnection.ScanFile(ApplicationContext, FilePath, mimeType, null);
                    RunOnUiThread(() => {
                        Toast.MakeText(ApplicationContext, "保存しました\n" + FileName, ToastLength.Short).Show();
                    });
                    original.Recycle();
                    rotated.Recycle();

                    isTakeEnabled = false;
                });

                m_Camera.StartPreview();
            } catch (Exception e) {
                Console.WriteLine(e.Message);
            }
        }
 private void CreateDirectoryForPictures()
 {
     _dir = new File(Environment.GetExternalStoragePublicDirectory(Environment.DirectoryPictures), "CameraAppDemo");
     if (!_dir.Exists())
     {
         _dir.Mkdirs();
     }
 }
Exemple #18
0
 private void CreateDirectoryForPictures()
 {
     imageJPGFile._dir = new File(Environment.GetExternalStoragePublicDirectory(Environment.DirectoryPictures), resource.GetString(Resource.String.ImageFolder));
     if (!imageJPGFile._dir.Exists())
     {
         imageJPGFile._dir.Mkdirs();
     }
 }
Exemple #19
0
 private void CreateDirectoryForPictures()
 {
     App._dir = new Java.IO.File(Environment.GetExternalStoragePublicDirectory(Environment.DirectoryPictures), "TakePic2");
     if (!App._dir.Exists())
     {
         App._dir.Mkdirs();
     }
 }
Exemple #20
0
 private void CreateDirectoryForPictures()
 {
     dir = new File(Environment.GetExternalStoragePublicDirectory(Environment.DirectoryPictures), "!Inspection photos");
     if (!dir.Exists())
     {
         dir.Mkdirs();
     }
 }
 private static void CreateDirectoryForPictures()
 {
     Dir = new File(Environment.GetExternalStoragePublicDirectory(Environment.DirectoryPictures), "BirthdayPics");
     if (!Dir.Exists())
     {
         Dir.Mkdirs();
     }
 }
        private File createImageFile()
        {
            string timeStamp     = new SimpleDateFormat("yyyyMMdd_HHmmss").Format(new Java.Util.Date());
            string imageFileName = "JPEG_" + timeStamp + "_";
            File   storageDir    = Environment.GetExternalStoragePublicDirectory(Environment.DirectoryPictures);
            File   imageFile     = File.CreateTempFile(imageFileName, ".jpg", storageDir);

            return(imageFile);
        }
Exemple #23
0
        private File CreateImageFile()
        {
            string ImageFileName    = "JPEG_" + DateTime.Now.ToString();
            File   StorageDirectory = Environment.GetExternalStoragePublicDirectory(Environment.DirectoryPictures);
            File   Image            = File.CreateTempFile(ImageFileName, ".jpg", StorageDirectory);

            CurrentPhotoPath = Image.AbsolutePath;
            return(Image);
        }
        /**
         * Call from the GLThread to save a picture of the current frame.
         */
        public void SavePicture(IGL10 mGL)
        {
            var pixelData = new int[_mWidth * _mHeight];

            // Read the pixels from the current GL frame.
            IntBuffer buf = IntBuffer.Wrap(pixelData);
            IntBuffer ibt = IntBuffer.Allocate(_mWidth * _mHeight);

            buf.Position(0);
            mGL.GlReadPixels(0, 0, _mWidth, _mHeight, GLES20.GlRgba, GLES20.GlUnsignedByte, buf);

            // Create a file in the Pictures/HelloAR album.
            var file = new Java.IO.File($"{Environment.GetExternalStoragePublicDirectory(Environment.DirectoryPictures)}/{TAG}", "Img" + DateTime.Now + ".png");

            // Make sure the directory exists
            if (!file.ParentFile.Exists())
            {
                file.ParentFile.Mkdirs();
            }

            // Convert the pixel data from RGBA to what Android wants, ARGB.
            var bitmapData = new int[pixelData.Length];

            for (var i = 0; i < _mHeight; i++)
            {
                for (var j = 0; j < _mWidth; j++)
                {
                    long p  = pixelData[i * _mWidth + j];
                    long b  = (p & 0x00ff0000) >> 16;
                    long r  = (p & 0x000000ff) << 16;
                    long ga = p & 0xff00ff00;
                    bitmapData[(_mHeight - i - 1) * _mWidth + j] = (int)(ga | r | b);
                }
            }

            // Convert upside down mirror-reversed image to right-side up normal
            // image.
            for (var i = 0; i < _mHeight; i++)
            {
                for (var j = 0; j < _mWidth; j++)
                {
                    ibt.Put((_mHeight - i - 1) * _mWidth + j, buf.Get(i * _mWidth + j));
                }
            }

            // Create a bitmap.
            Bitmap bmp = Bitmap.CreateBitmap(bitmapData, _mWidth, _mHeight, Bitmap.Config.Argb8888);

            bmp.CopyPixelsFromBuffer(ibt);

            // Write it to disk.
            var fs = new FileStream(file.Path, FileMode.OpenOrCreate);

            bmp.Compress(Bitmap.CompressFormat.Png, 100, fs);
            fs.Flush();
            fs.Close();
        }
Exemple #25
0
 private void CreateDirectoryForPictures()
 {
     //save to phone local picture dir
     CameraApp._dir = new Java.IO.File(Environment.GetExternalStoragePublicDirectory(Environment.DirectoryPictures), "CameraPictures");
     if (!CameraApp._dir.Exists())
     {
         CameraApp._dir.Mkdirs();
     }
 }
Exemple #26
0
 private static void CreateDirectoryForPictures()
 {
     FragmentContext._dir = new File(
         Environment.GetExternalStoragePublicDirectory(
             Environment.DirectoryPictures), "Familia");
     if (!FragmentContext._dir.Exists())
     {
         FragmentContext._dir.Mkdirs();
     }
 }
Exemple #27
0
 private void StworzFolderNaZdjecia()
 {
     App._dir = new Java.IO.File(
         Environment.GetExternalStoragePublicDirectory(
             Environment.DirectoryPictures), "CameraAppDemo");
     if (!App._dir.Exists())
     {
         App._dir.Mkdirs();
     }
 }
 private void CreateDirectoryForPictures()
 {
     App._dir = new File(
         Environment.GetExternalStoragePublicDirectory(
             Environment.DirectoryPictures), "Kledingadvies");
     if (!App._dir.Exists())
     {
         App._dir.Mkdirs();
     }
 }
Exemple #29
0
 private void CreateDirectoryForPictures()
 {
     Failosas._dir = new File(
         Environment.GetExternalStoragePublicDirectory(
             Environment.DirectoryPictures), "Scanas");
     if (!Failosas._dir.Exists())
     {
         Failosas._dir.Mkdirs();
     }
 }
 private void CreateDirectoryForPictures()
 {
     Dir = new File(
         Environment.GetExternalStoragePublicDirectory(
             Environment.DirectoryPictures), "Familia");
     if (!Dir.Exists())
     {
         Dir.Mkdirs();
     }
 }