Ejemplo n.º 1
0
        public string GetAbsolutePathToFile(string fileName)
        {
            string dir;

            if (PublicStorage)
            {
                if (string.IsNullOrWhiteSpace(directoryType))
                {
                    dir = Environment.ExternalStorageDirectory.AbsolutePath;
                }
                else
                {
                    dir = Environment.GetExternalStoragePublicDirectory(directoryType).AbsolutePath;
                }
            }
            else
            {
                if (!contextRef.TryGetTarget(out Context c))
                {
                    return(null);
                }

                dir = c.GetExternalFilesDir(directoryType).AbsolutePath;
            }

            return(Path.Combine(dir, fileName));
        }
        public async Task SharePoster(string title, string image)
        {
            var intent = new Intent(Intent.ActionSend);

            intent.SetType("image/png");
            Guid guid = Guid.NewGuid();
            var  path = Environment.GetExternalStoragePublicDirectory(Environment.DataDirectory
                                                                      + Java.IO.File.Separator + guid + ".png");

            HttpClient client       = new HttpClient();
            var        httpResponse = await client.GetAsync(image);

            byte[] imageBuffer = await httpResponse.Content.ReadAsByteArrayAsync();

            if (File.Exists(path.AbsolutePath))
            {
                File.Delete(path.AbsolutePath);
            }

            using (var os = new System.IO.FileStream(path.AbsolutePath, System.IO.FileMode.Create))
            {
                await os.WriteAsync(imageBuffer, 0, imageBuffer.Length);
            }

            intent.PutExtra(Intent.ExtraStream, Android.Net.Uri.FromFile(path));

            var intentChooser = Intent.CreateChooser(intent, "Share via");

            Activity activity = Forms.Context as Activity;

            activity.StartActivityForResult(intentChooser, 100);
        }
        protected override async Task InitializeAsync()
        {
            await base.InitializeAsync();

            if (await SensusServiceHelper.Get().ObtainPermissionAsync(Permission.Storage) == PermissionStatus.Granted)
            {
                // Different phones and camera apps can save images in different physical locations, so look at the last QUERY_LAST_IMAGE_COUNT number of images and observe the location(s) they were saved in.
                ICursor       cursor = Application.Context.ContentResolver.Query(MediaStore.Images.Media.ExternalContentUri, new string[] { MediaStore.Images.Media.InterfaceConsts.Data }, null, null, MediaStore.Images.Media.InterfaceConsts.DateTaken + $" DESC LIMIT {QUERY_LAST_IMAGE_COUNT}");
                List <string> paths  = new List <string> {
                    Environment.GetExternalStoragePublicDirectory(Environment.DirectoryDcim).CanonicalPath
                };

                while (cursor.MoveToNext())
                {
                    string path = cursor.GetString(cursor.GetColumnIndex(MediaStore.Images.Media.InterfaceConsts.Data));
                    Uri    uri  = Uri.Parse(path);

                    path = File.Separator + Path.Combine(uri.PathSegments.Take(uri.PathSegments.Count - 1).ToArray());

                    if (paths.Any(x => path.StartsWith(x)) == false)
                    {
                        paths.Add(path);
                    }
                }

                _fileObservers = paths.Distinct().Select(x => new AndroidImageFileObserver(x, this)).ToList();
            }
            else
            {
                throw new Exception("Failed to obtain Storage permission from user.");
            }
        }
        public async Task <string> SaveTaggedImageAsync(string fileName, FileTaggingInformation taggingInformation,
                                                        byte[] image)
        {
            var imagesFolder = Environment.GetExternalStoragePublicDirectory(Environment.DirectoryDcim);
            var imagesPath   = imagesFolder.AbsolutePath;
            var taggedFolder = Path.Combine(imagesPath, "Tagged");

            var filePath = Path.Combine(taggedFolder, fileName);

            try
            {
                var imageData = await GetTaggedImageFromUriAsync(taggingInformation, image);

                if (!Directory.Exists(taggedFolder))
                {
                    Directory.CreateDirectory(taggedFolder);
                }

                File.WriteAllBytes(filePath, imageData);

                var mediaScanIntent = new Intent(Intent.ActionMediaScannerScanFile);
                mediaScanIntent.SetData(Uri.FromFile(new Java.IO.File(filePath)));
                Forms.Context.SendBroadcast(mediaScanIntent);
            }
            catch (Exception ex)
            {
            }

            return(string.Empty);
        }
        public async Task <bool> SaveBitmap(byte[] bitmapData, string filename)
        {
            try
            {
                File picturesDirectory  = Environment.GetExternalStoragePublicDirectory(Environment.DirectoryPictures);
                File spinPaintDirectory = new File(picturesDirectory, "PhotoCollage");
                spinPaintDirectory.Mkdirs();

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

                    using (FileOutputStream outputStream = new FileOutputStream(bitmapFile))
                    {
                        await outputStream.WriteAsync(bitmapData);
                    }
                    MediaScannerConnection.ScanFile(Android.App.Application.Context, new string[] { bitmapFile.Path }, new string[] { "image/png", "image/jpeg" }, null);
                    return(true);
                }
            }
            catch (Exception ex)
            {
                Toast.MakeText(Android.App.Application.Context, ex.Message, ToastLength.Long).Show();
                return(false);
            }
        }
Ejemplo n.º 6
0
        private async Task SaveSmallImage(byte[] imageData, float width, float height, string fileName)
        {
            // Load the bitmap
            Bitmap originalImage = BitmapFactory.DecodeByteArray(imageData, 0, imageData.Length);

            //var scale = (int)width / originalImage.Width;

            //var newWidth = originalImage.Width * scale;
            //var newHeight = originalImage.Height * scale;

            Bitmap resizedImage = Bitmap.CreateScaledBitmap(originalImage, (int)width, (int)height, false);

            using (MemoryStream ms = new MemoryStream())
            {
                resizedImage.Compress(Bitmap.CompressFormat.Jpeg, 100, ms);
                var imageFile = System.IO.Path.Combine(Environment.GetExternalStoragePublicDirectory(Environment.DirectoryPictures).ToString(), "NewFolder");
                Directory.CreateDirectory(imageFile);
                var smallImageFile = System.IO.Path.Combine(imageFile, fileName + "-mdismall.jpg");

                using (var fileOutputStream = new FileOutputStream(smallImageFile))
                {
                    await fileOutputStream.WriteAsync(ms.ToArray());
                }
            }
        }
Ejemplo n.º 7
0
        private IList <string> RootDirectory()
        {
            var pathlist = new List <string>();

            try
            {
                var temp = new List <string>();

                pathlist.Add(Environment.GetExternalStoragePublicDirectory(
                                 Environment.DirectoryDocuments).AbsolutePath);
                pathlist.Add(Environment.GetExternalStoragePublicDirectory(
                                 Environment.DirectoryDownloads).AbsolutePath);
                pathlist.Add(Environment.GetExternalStoragePublicDirectory(
                                 Environment.DirectoryMusic).AbsolutePath);
                pathlist.Add(Environment.GetExternalStoragePublicDirectory(
                                 Environment.DirectoryDocuments).AbsolutePath);

                foreach (var path in pathlist)
                {
                    if (Directory.Exists(path: path))
                    {
                        temp.AddRange(collection: Directory.EnumerateDirectories(path: path).ToList());
                    }
                }
                pathlist.AddRange(collection: temp);
                return(pathlist);
            }
            catch (Exception e)
            {
                throw;
            }
        }
Ejemplo n.º 8
0
        public bool AppendText(string text)
        {
            try
            {
                // TODO: Add google drive api call
                var directory = Environment.GetExternalStoragePublicDirectory(Environment.DirectoryDocuments);
                var filePath  = Path.Combine(directory.Path, this._FileName);
                if (!directory.Exists())
                {
                    var dirMadeSuccessfully = directory.Mkdir();
                }

                if (File.Exists(filePath))
                {
                    File.AppendAllText(filePath, text);
                }
                else
                {
                    using (var file = File.Create(filePath))
                    {
                        file.Write(Encoding.ASCII.GetBytes(text), 0, text.Length);
                    }
                }

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Ejemplo n.º 9
0
        public async Task <string> SaveByteArrayAsImageFile(byte[] imageData, string fileName)
        {
            try
            {
                if (imageData == null || imageData.Length == 0)
                {
                    return(string.Empty);
                }

                var filename = System.IO.Path.Combine(Environment.GetExternalStoragePublicDirectory(Environment.DirectoryPictures).ToString(), "NewFolder");
                Directory.CreateDirectory(filename);
                filename = System.IO.Path.Combine(filename, fileName + "-mdilarge.jpg");

                await SaveSmallImage(imageData, 200, 200, fileName);

                using (var fileOutputStream = new FileOutputStream(filename))
                {
                    await fileOutputStream.WriteAsync(imageData);

                    return(filename);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
Ejemplo n.º 10
0
        public void View(string filePath)
        {
            var downloadpath =
                Environment.GetExternalStoragePublicDirectory(Environment.DirectoryDownloads).AbsolutePath;

            downloadpath = Path.Combine(downloadpath, filePath);
            var file   = new File(downloadpath);
            var uri    = Uri.FromFile(file);
            var intent = new Intent(Intent.ActionView);

            intent.SetDataAndType(uri, "application/pdf");

            if (!System.IO.File.Exists(downloadpath))
            {
                return;
            }

            try
            {
                Forms.Context.StartActivity(intent);
            }
            catch (Exception e)
            {
                //
            }
        }
        public async Task <List <string> > GetImageFileNamesAsync(IEnumerable <string> existingFileNames)
        {
            var tcs = new TaskCompletionSource <List <string> >();

            var imagesFolder = Environment.GetExternalStoragePublicDirectory(Environment.DirectoryDcim);

            var imagesPath = Path.Combine(imagesFolder.AbsolutePath, "Camera");

            if (!Directory.Exists(imagesPath))
            {
                Directory.CreateDirectory(imagesPath);
            }

            var files = Directory.GetFiles(imagesPath).ToList();

            List <string> fileNames = new List <string>();

            foreach (var file in files)
            {
                string fileName = file.Split("/\\".ToCharArray()).LastOrDefault();

                if (!existingFileNames.ToList().Contains(fileName))
                {
                    fileNames.Add(fileName);
                }
            }

            tcs.SetResult(fileNames);

            return(await tcs.Task);
        }
        /// <inheritdoc />
        public async Task SaveToCameraRoll(MediaFile mediafile, bool overwrite = true)
        {
            string targetFilename = mediafile.Filename;

            this.tracer.Debug("SaveToCameraRoll with targetFilename={0}, overwrite={1}", targetFilename, overwrite);

            var picturesDirectory = new File(Environment.GetExternalStoragePublicDirectory(Environment.DirectoryPictures).AbsolutePath);

            if (picturesDirectory.Exists())
            {
                this.tracer.Debug("Creating directory {0} since it does not exist.", picturesDirectory.AbsolutePath);
                picturesDirectory.Mkdirs();
            }

            var sourcePath = mediafile.Path;
            var targetPath = System.IO.Path.Combine(picturesDirectory.AbsolutePath, targetFilename);

            this.tracer.Debug("Copying {0} to {1}.", sourcePath, targetPath);
            System.IO.File.Copy(sourcePath, targetPath, overwrite);

            // Make it available in the gallery
            Intent mediaScanIntent = new Intent(Intent.ActionMediaScannerScanFile);
            Uri    contentUri      = Uri.FromFile(new File(targetPath));

            this.tracer.Debug("Broadcasting contentUri={0} to media gallery.", contentUri.Path);

            mediaScanIntent.SetData(contentUri);

            this.context.SendBroadcast(mediaScanIntent);
        }
Ejemplo n.º 13
0
        public string GetFilePath(string filename)
        {
            Java.IO.File sdDir    = Environment.GetExternalStoragePublicDirectory(filename);
            string       filepath = sdDir.AbsolutePath;

            return(filepath);
        }
Ejemplo n.º 14
0
        public string LoadText()
        {
            // TODO: Add google drive api call
            var directory = Environment.GetExternalStoragePublicDirectory(Environment.DirectoryDocuments);
            var filePath  = Path.Combine(directory.Path, this._FileName);

            return(File.ReadAllText(filePath));
        }
Ejemplo n.º 15
0
        public bool FileExists(string filePath)
        {
            var downloadpath =
                Environment.GetExternalStoragePublicDirectory(Environment.DirectoryDownloads).AbsolutePath;

            downloadpath = Path.Combine(downloadpath, filePath);

            return(System.IO.File.Exists(downloadpath));
        }
Ejemplo n.º 16
0
                static void CreateDirectoryForPictures()
                {
                    Pic.Dir = new File(Environment.GetExternalStoragePublicDirectory(Environment.DirectoryPictures), "PULSE");

                    if (!Pic.Dir.Exists())
                    {
                        Pic.Dir.Mkdirs();
                    }
                }
Ejemplo n.º 17
0
        public FileHelper(string fileName = "ConfigClient.txt")
        {
            try
            {
                Path = Environment.GetExternalStoragePublicDirectory(Environment.DirectoryDownloads).Path;

                Filename = System.IO.Path.Combine(Path, fileName);
            }
            catch (Exception e)
            {
                Log.Debug("FH ctor:", e.Message);
            }
        }
        public async Task <List <LocalFileInformation> > GetImagesAsync(IEnumerable <string> existingFileNames)
        {
            var tcs = new TaskCompletionSource <List <LocalFileInformation> >();

            var images = new List <LocalFileInformation>();

            var imagesFolder = Environment.GetExternalStoragePublicDirectory(Environment.DirectoryDcim);

            var imagesPath = Path.Combine(imagesFolder.AbsolutePath, "Camera");

            if (!Directory.Exists(imagesPath))
            {
                Directory.CreateDirectory(imagesPath);
            }

            var files         = Directory.GetFiles(imagesPath).ToList();
            var filteredFiles = files.Where(w => !existingFileNames.Contains(w.Split("/\\d".ToCharArray()).LastOrDefault()));

            foreach (var file in filteredFiles.Take(Common.CoreConstants.ImageCountLimit))
            {
                var fileSize = new FileInfo(file).Length;

                try
                {
                    byte[] imageBytes = null;

                    imageBytes = File.ReadAllBytes(file);

                    if (imageBytes.Length < (int)Common.CoreConstants.ImageSizeLimit)
                    {
                        images.Add(new LocalFileInformation
                        {
                            FileName    = file.Split('\\').LastOrDefault(),
                            Url         = file,
                            File        = imageBytes,
                            CreatedDate = File.GetLastWriteTime(file)
                        });
                    }
                }
                catch (Exception ex)
                {
                }
            }

            tcs.SetResult(images);

            return(await tcs.Task);
        }
        /// <summary>
        /// A public folder representing storage which contains Pictures.
        /// </summary>
        public Task <IFolder> PicturesFolderAsync()
        {
            var folderPath = "";

            if (AndroidHelpers.IsExternalStorageWritable())
            {
                var f = AndroidEnvironment.GetExternalStoragePublicDirectory(AndroidEnvironment.DirectoryPictures);
                folderPath = f.Path;
            }
            else
            {
                return(null);
            }

            return(Task.FromResult((IFolder) new DroidFileSystemFolder(folderPath, Storage.Pictures)));
        }
Ejemplo n.º 20
0
        partial void SaveImage(SurfaceSaver surfaceSaver, RenderTarget2D target)
        {
            var filename = $"output-{DateTime.Now:yyyyMMdd-HHmmss}.png";

            var dir = AndroidEnvironment.GetExternalStoragePublicDirectory(
                AndroidEnvironment.DirectoryPictures).AbsolutePath;
            var path = Path.Combine(dir, filename);

            using (var stream = File.OpenWrite(path))
                surfaceSaver.SaveAsPng(rtarget, stream);

            MediaScannerConnection.ScanFile(ApplicationContext, new String[] { path },
                                            new String[] { MimeTypeMap.Singleton.GetMimeTypeFromExtension("png") }, null);

            confirmMsgText    = $"Image saved to photo gallery";
            confirmMsgOpacity = 1;
        }
Ejemplo n.º 21
0
        /**
         * Creates a media file in the {@code Environment.DIRECTORY_PICTURES} directory. The directory
         * is persistent and available to other applications like gallery.
         *
         * @param type Media type. Can be video or image.
         * @return A file object pointing to the newly created file.
         */
        public static File getOutputMediaFile(int type)
        {
            // To be safe, you should check that the SDCard is mounted
            // using Environment.getExternalStorageState() before doing this.
            if (!string.Equals(Environment.ExternalStorageState, Environment.MediaMounted, StringComparison.OrdinalIgnoreCase))
            {
                return(null);
            }

            File mediaStorageDir = new File(Environment.GetExternalStoragePublicDirectory(
                                                Environment.DirectoryPictures), "CameraSample");

            // This location works best if you want the created images to be shared
            // between applications and persist after your app has been uninstalled.

            // Create the storage directory if it does not exist
            if (!mediaStorageDir.Exists())
            {
                if (!mediaStorageDir.Mkdirs())
                {
                    Log.Debug("CameraSample", "failed to create directory");
                    return(null);
                }
            }

            // Create a media file name
            String timeStamp = DateTime.UtcNow.ToString("yyyyMMdd_HHmmss");
            File   mediaFile;

            if (type == MEDIA_TYPE_IMAGE)
            {
                mediaFile = new File(mediaStorageDir.Path + File.Separator +
                                     "IMG_" + timeStamp + ".jpg");
            }
            else if (type == MEDIA_TYPE_VIDEO)
            {
                mediaFile = new File(mediaStorageDir.Path + File.Separator +
                                     "VID_" + timeStamp + ".mp4");
            }
            else
            {
                return(null);
            }

            return(mediaFile);
        }
Ejemplo n.º 22
0
        public async Task <bool> SavePhotoAsnyc(byte[] data, string folder, string filename)
        {
            try
            {
                if (ContextCompat.CheckSelfPermission(MainActivity.Instance, Manifest.Permission.WriteExternalStorage) != PermissionChecker.PermissionGranted)
                {
                    ActivityCompat.RequestPermissions(MainActivity.Instance, new string[] { Manifest.Permission.WriteExternalStorage }, 1000);
                }


                File picturesDirectory = Environment.GetExternalStoragePublicDirectory(Environment.DirectoryPictures);
                File folderDirectory;

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

                using (File bitmapFile = new File("/storage/emulated/0/Download", filename))
                {
                    bitmapFile.CreateNewFile();

                    using (FileStream outputStream = new FileStream(bitmapFile.ToString(), FileMode.Open))
                    {
                        await outputStream.WriteAsync(data);
                    }

                    // Make sure it shows up in the Photos gallery promptly.
                    MediaScannerConnection.ScanFile(MainActivity.Instance,
                                                    new string[] { bitmapFile.Path },
                                                    new string[] { "image/png", "image/jpeg" }, null);
                }
            }
            catch
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 23
0
        public void CameraMedia()
        {
            AppClass._dir = new Java.IO.File(Environment.GetExternalStoragePublicDirectory(Environment.DirectoryPictures), "RedButton");
            if (!AppClass._dir.Exists())
            {
                AppClass._dir.Mkdirs();
            }

            Intent intent = new Intent(MediaStore.ActionImageCapture);

            AppClass._file = new Java.IO.File(AppClass._dir, String.Format("myPhoto_{0}.jpg", Guid.NewGuid()));

            intent.PutExtra(MediaStore.ExtraOutput, Uri.FromFile(AppClass._file));

            Activity activity = (Activity)Forms.Context;

            activity.StartActivityForResult(intent, 0);
        }
        public void SaveImage(string fileName, byte[] fileBytes)
        {
            var imagesFolder = Environment.GetExternalStoragePublicDirectory(Environment.DirectoryDcim);
            var imagesPath   = imagesFolder.AbsolutePath;

            var filePath = Path.Combine(imagesPath, "Camera", fileName);

            try
            {
                File.WriteAllBytes(filePath, fileBytes);

                var mediaScanIntent = new Intent(Intent.ActionMediaScannerScanFile);
                mediaScanIntent.SetData(Uri.FromFile(new Java.IO.File(filePath)));
                Forms.Context.SendBroadcast(mediaScanIntent);
            }
            catch (Exception ex)
            {
            }
        }
        public void SavePictureToDisk(string filename, byte[] imageData)
        {
            var dir      = Environment.GetExternalStoragePublicDirectory(Environment.DirectoryDcim);
            var pictures = dir.AbsolutePath;

            string name     = filename + System.DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".jpg";
            string filePath = System.IO.Path.Combine(pictures, name);

            try
            {
                System.IO.File.WriteAllBytes(filePath, imageData);
                var mediaScanIntent = new Intent(Intent.ActionMediaScannerScanFile);
                mediaScanIntent.SetData(Uri.FromFile(new File(filePath)));
                Xamarin.Forms.Forms.Context.SendBroadcast(mediaScanIntent);
            }
            catch (System.Exception e)
            {
                System.Console.WriteLine(e.ToString());
            }
        }
Ejemplo n.º 26
0
        public static File CreateImageFile(string name)
        {
            // Create an image file name
            File storageDir = new File(Environment.GetExternalStoragePublicDirectory(Environment.DirectoryPictures) + "/MALClient/");
            var  chars      = Path.GetInvalidFileNameChars();
            var  cleanName  = name.Aggregate("", (s, c) =>
            {
                if (!chars.Contains(c))
                {
                    s += c;
                }
                return(s);
            });

            cleanName += ".png";
            File image = new File(storageDir, cleanName);

            if (!storageDir.Exists())
            {
                storageDir.Mkdirs();
            }
            return(image);
        }
Ejemplo n.º 27
0
        public Task <CameraResult> TakePictureAsync()
        {
            Intent intent = new Intent(MediaStore.ActionImageCapture);

            pictureDirectory = new File(Environment.GetExternalStoragePublicDirectory(Environment.DirectoryPictures), "CameraAppDemo");

            if (!pictureDirectory.Exists())
            {
                pictureDirectory.Mkdirs();
            }

            file = new File(pictureDirectory, String.Format("photo_{0}.jpg", Guid.NewGuid()));

            intent.PutExtra(MediaStore.ExtraOutput, Uri.FromFile(file));

            var activity = (Activity)Forms.Context;

            activity.StartActivityForResult(intent, 0);

            tcs = new TaskCompletionSource <CameraResult>();

            return(tcs.Task);
        }
Ejemplo n.º 28
0
        /*private void ObjectItemLongClicked
         * (
         *  object sender,
         *  AdapterView.ItemLongClickEventArgs arguments
         * )
         * {
         *  PortableSyncRenderer<Context> selectedObject = _browseObjectsAdapter[arguments.Position];
         *
         *  selectedObject.EditObject(this,
         *                            deviceOrientation : 0);
         * }*/

        private void AddImageClicked()
        {
            var imageDirectory = new File
                                 (
                Environment.GetExternalStoragePublicDirectory(Environment.DirectoryPictures),

                PackageName
                                 );

            if (imageDirectory.Exists() == false)
            {
                imageDirectory.Mkdirs();
            }

            var imageFile = new File(imageDirectory,
                                     string.Format("Receipt_{0}.jpg", Guid.NewGuid()));

            var addImageIntent = new Intent(this, typeof(AndroidAddImageActivity));

            addImageIntent.PutExtra(AndroidAddImageActivity.PicturePathExtra,
                                    imageFile.Path);

            StartActivity(addImageIntent);
        }
Ejemplo n.º 29
0
        //http://stackoverflow.com/questions/477572/strange-out-of-memory-issue-while-loading-an-image-to-a-bitmap-object/823966#823966


        public static async void SaveBitmapAsJPG()
        {
            var path = new File(
                Environment.GetExternalStoragePublicDirectory(Environment.DirectoryPictures), "OCR").AbsolutePath;
            var smallfilePath = System.IO.Path.Combine(path, "small.jpg");
            var bigfilePath   = System.IO.Path.Combine(path, "OCR.jpg");

            BitmapFactory.Options opts = new BitmapFactory.Options();

            // load the image and have BitmapFactory resize it for us.
            opts.InSampleSize       = 4;     //  1/4 size
            opts.InJustDecodeBounds = false; //set to false to get the whole image not just the bounds
            Bitmap bitmap = await BitmapFactory.DecodeFileAsync(bigfilePath, opts);


            //rotate a bmp
            Matrix matrix = new Matrix();

            matrix.PostRotate(90);
            var rotatedBitmap = Bitmap.CreateBitmap(bitmap, 0, 0, bitmap.Width, bitmap.Height, matrix, true);


            //write it back
            using (var stream = new FileStream(smallfilePath, FileMode.Create))
            {
                //70% compressed
                await rotatedBitmap.CompressAsync(Bitmap.CompressFormat.Jpeg, 70, stream);

                stream.Close();
            }

            //    await stream.FlushAsync();
            // Free the native object associated with this bitmap, and clear the reference to the pixel data. This will not free the pixel data synchronously; it simply allows it to be garbage collected if there are no other references. The bitmap is marked as "dead", meaning it will throw an exception if getPixels() or setPixels() is called, and will draw nothing.
            //  bitmap.Recycle();
            //     GC.Collect();
        }
Ejemplo n.º 30
0
 public string GetPathPictures() => Environment.GetExternalStoragePublicDirectory(Environment.DirectoryPictures).Path;