private void StartProcessing() //even slower than startAllProcessing that uses surface { _framelist = new SortedList <long, SparseArray>(); var toast = Toast.MakeText(this, "Starting processing please wait.....", ToastLength.Long); toast.Show(); Java.IO.File file = new Java.IO.File(_downloadsfilesdir, _inputfilename); var decoder = new FramesExtract(); Task.Run(() => decoder.PrepareEncoder(file.AbsolutePath, _downloadsfilesdir)); //decoder.PrepareEncoder(file.AbsolutePath); //decoder.Decode(); //var encodedimagedata = FramesExtract.GetFrames(this, file.AbsolutePath); //foreach (var data in encodedimagedata) //{ // Bitmap bmp = Bitmap.CreateBitmap(640, 360, Bitmap.Config.Argb8888); // bmp.CopyPixelsFromBuffer(data.Value); // var createfilepath = new Java.IO.File(_downloadsfilesdir, DateTime.Now.Ticks + ".bmp").AbsolutePath; // using (FileStream bos = new FileStream(createfilepath, FileMode.CreateNew)) // { // bmp.Compress(Bitmap.CompressFormat.Png, 90, bos); // } // bmp.Recycle(); //} }
private Task <bool> CreateTrimVideo(Tuple <long, long> _bestts) { Java.IO.File inputFile = new Java.IO.File(_downloadsfilesdir, _inputfilename); var outputfilename = string.Format("{0}.mp4", DateTime.Now.Ticks); Java.IO.File outputFile = new Java.IO.File(_downloadsfilesdir, outputfilename); _outputfilepath = outputFile.Path; var result = VideoUtils.startTrim(inputFile, outputFile, _bestts.Item1, _bestts.Item2); return(Task.FromResult(result)); }
private async Task CreateTestByteFileCache(byte[] bytes) { var context = Application.Context; var cacheFile = new Java.IO.File(context.CacheDir.AbsolutePath, Filename); if (cacheFile.Exists()) { cacheFile.Delete(); } cacheFile.CreateNewFile(); var fo = new FileOutputStream(cacheFile); await fo.WriteAsync(bytes); fo.Close(); }
public void OpenImage(string Directory, string image, string Userid) { try { if (Directory == "Disk") { var documentsDirectory = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal) + "/" + Userid; string Image = image.Split('/').Last(); string FilePath = System.IO.Path.Combine(documentsDirectory, Image); var bytes = File.ReadAllBytes(FilePath); var externalPath = global::Android.OS.Environment.ExternalStorageDirectory.Path + "/MaterialsReg/" + FilePath; DirectoryInfo dirInfo = System.IO.Directory.CreateDirectory(externalPath.Remove(externalPath.LastIndexOf('/'))); File.WriteAllBytes(externalPath, bytes); Java.IO.File file = new Java.IO.File(externalPath); file.SetReadable(true); Android.Net.Uri uri = Android.Net.Uri.FromFile(file); Intent intent = new Intent(Intent.ActionView); intent.SetDataAndType(uri, "image/*"); intent.SetFlags(ActivityFlags.ClearWhenTaskReset | ActivityFlags.NewTask); ((MainActivity)Xamarin.Forms.Forms.Context).StartActivity(intent); } else if (Directory == "Galary") { var dir = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDcim); string Image = image.Split('/').Last(); string FilePath = System.IO.Path.Combine(dir + "/" + WowonderPhone.Settings.ApplicationName + "/", Image); Intent intent = new Intent(); intent.SetAction(Android.Content.Intent.ActionView); Android.Net.Uri uri = Android.Net.Uri.FromFile(new Java.IO.File(FilePath)); intent.SetDataAndType(uri, "image/*"); ((MainActivity)Xamarin.Forms.Forms.Context).StartActivity(intent); } else { Intent intent = new Intent(); intent.SetAction(Android.Content.Intent.ActionView); Android.Net.Uri uri = Android.Net.Uri.FromFile(new Java.IO.File(image)); intent.SetDataAndType(uri, "image/*"); ((MainActivity)Xamarin.Forms.Forms.Context).StartActivity(intent); } } catch (Exception) { } }
public static void Download(string imageUrl, string fileName, string title = "") { try { if (string.IsNullOrEmpty(imageUrl) || Activity == null) { return; } Uri photoUri; Activity.RunOnUiThread(() => { try { var getImage = Methods.MultiMedia.GetMediaFrom_Gallery(Methods.Path.FolderDcimImage, fileName); if (getImage != "File Dont Exists") { Java.IO.File file2 = new Java.IO.File(getImage); photoUri = FileProvider.GetUriForFile(Activity, Activity.PackageName + ".fileprovider", file2); ShareLocalFile(photoUri, imageUrl, title); } else { string filePath = Path.Combine(Methods.Path.FolderDcimImage); string mediaFile = filePath + "/" + fileName; if (!Directory.Exists(filePath)) { Directory.CreateDirectory(filePath); } if (!File.Exists(mediaFile)) { AndHUD.Shared.Show(Activity, Activity.GetText(Resource.String.Lbl_Loading)); WebClient webClient = new WebClient(); webClient.DownloadDataAsync(new System.Uri(imageUrl)); webClient.DownloadDataCompleted += (s, e) => { try { File.WriteAllBytes(mediaFile, e.Result); var getImagePath = Methods.MultiMedia.GetMediaFrom_Gallery(Methods.Path.FolderDcimImage, fileName); if (getImagePath != "File Dont Exists") { Java.IO.File file2 = new Java.IO.File(getImagePath); photoUri = FileProvider.GetUriForFile(Activity, Activity.PackageName + ".fileprovider", file2); ShareLocalFile(photoUri, imageUrl, title); } } catch (Exception exception) { Methods.DisplayReportResultTrack(exception); } //var mediaScanIntent = new Intent(Intent?.ActionMediaScannerScanFile); //mediaScanIntent?.SetData(Uri.FromFile(new Java.IO.File(mediaFile))); //Activity.SendBroadcast(mediaScanIntent); // Tell the media scanner about the new file so that it is // immediately available to the user. MediaScannerConnection.ScanFile(Application.Context, new[] { mediaFile }, null, null); }; AndHUD.Shared.Dismiss(Activity); } } } catch (Exception e) { Methods.DisplayReportResultTrack(e); } }); } catch (Exception e) { Methods.DisplayReportResultTrack(e); } }
public Intent SaveAndView(string fileName, string contentType, MemoryStream stream, PDFOpenContext context, Context appctx) { string exception = string.Empty; string root = null; if (Android.OS.Environment.IsExternalStorageEmulated) { root = Android.OS.Environment.ExternalStorageDirectory.ToString(); } else { root = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); } Java.IO.File myDir = new Java.IO.File(root + "/PDFFiles"); myDir.Mkdir(); Java.IO.File file = new Java.IO.File(myDir, fileName); if (file.Exists()) { file.Delete(); } try { FileOutputStream outs = new FileOutputStream(file); outs.Write(stream.ToArray()); outs.Flush(); outs.Close(); } catch (Exception e) { exception = e.ToString(); return(null); } if (file.Exists() && contentType != "application/html") { string extension = MimeTypeMap.GetFileExtensionFromUrl(Android.Net.Uri.FromFile(file).ToString()); string mimeType = MimeTypeMap.Singleton.GetMimeTypeFromExtension(extension); Intent intent = new Intent(Intent.ActionView); intent.SetFlags(ActivityFlags.ClearTop | ActivityFlags.NewTask); Android.Net.Uri path = FileProvider.GetUriForFile(appctx, Android.App.Application.Context.PackageName + ".fileprovider", file); intent.SetDataAndType(path, mimeType); intent.AddFlags(ActivityFlags.GrantReadUriPermission); return(intent); //switch (context) //{ // case PDFOpenContext.InApp: // appctx.StartActivity(intent); // break; // case PDFOpenContext.ChooseApp: // appctx.StartActivity(Intent.CreateChooser(intent, "Choose App")); // break; // default: // break; //} } else { return(null); } }