protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data) { base.OnActivityResult(requestCode, resultCode, data); // Deixa a imagem disponível na galeria de imagens Intent mediaScanIntent = new Intent(Intent.ActionMediaScannerScanFile); Android.Net.Uri contentUri = Android.Net.Uri.FromFile(ImageData.Arquivo); mediaScanIntent.SetData(contentUri); SendBroadcast(mediaScanIntent); //Define o tamanho da imagem int height = Resources.DisplayMetrics.HeightPixels; int width = Resources.DisplayMetrics.WidthPixels; //Obtendo dados da imagem var imgFile = new Java.IO.File(ImageData.Arquivo.Path); var stream = new Java.IO.FileInputStream(imgFile); var bytes = new byte[imgFile.Length()]; stream.Read(bytes); MessagingCenter.Send <byte[]>(bytes, "TirarFoto"); // Fazendo dispose da imagem no Java GC.Collect(); }
private void PlayRecording(object sender, EventArgs e) { Label l = (Label)sender; Java.IO.File tempFile = Java.IO.File.CreateTempFile($"{l.Text}", ".mp3"); Models.AudioRecord ar = (Models.AudioRecord)l.BindingContext; if (!mp.IsPlaying) { FileOutputStream fos = new Java.IO.FileOutputStream(tempFile); fos.Write(ar.AudioClip); fos.Close(); mp.Reset(); //string path = $"{Android.OS.Environment.ExternalStorageDirectory.AbsolutePath}/{l.Text}.mp3"; Java.IO.FileInputStream fis = new Java.IO.FileInputStream(tempFile); mp.SetDataSource(fis.FD); mp.Prepare(); mp.Start(); } else { mp.Stop(); mp.Release(); tempFile.Delete(); } }
public void ResizeImage(string sourceFile, string targetFile, float maxWidth, float maxHeight) { var permissions = new string[] { Manifest.Permission.ReadExternalStorage, Manifest.Permission.WriteExternalStorage }; RequestPermissions(permissions, 77); Bitmap bitmapScaled; // First decode with inJustDecodeBounds=true to check dimensions var options = new BitmapFactory.Options() { InJustDecodeBounds = false, InPurgeable = true, }; var image = BitmapFactory.DecodeFile(sourceFile, options); //if (image != null) //{ var sourceSize = new System.Drawing.Size((int)image.GetBitmapInfo().Height, (int)image.GetBitmapInfo().Width); var maxResizeFactor = Math.Min(maxWidth / sourceSize.Width, maxHeight / sourceSize.Height); string targetDir = System.IO.Path.GetDirectoryName(targetFile); if (!Directory.Exists(targetDir)) { Directory.CreateDirectory(targetDir); } Java.IO.File diretorio = new Java.IO.File( Android.OS.Environment.GetExternalStoragePublicDirectory( Android.OS.Environment.DirectoryPictures), "Imagens"); var width = (int)(maxResizeFactor * sourceSize.Width); var height = (int)(maxResizeFactor * sourceSize.Height); bitmapScaled = Bitmap.CreateScaledBitmap(image, 4096, 3072, true); var stream = new Java.IO.FileInputStream(arquivoImagem); using (Stream outStream = System.IO.File.Create($"{targetDir}/Testes.jpg")) { if (targetFile.ToLower().EndsWith("png")) { bitmapScaled.Compress(Bitmap.CompressFormat.Png, 100, outStream); } else { bitmapScaled.Compress(Bitmap.CompressFormat.Jpeg, 80, outStream); } var bytesss = bitmapScaled.ByteCount; var teste = 1; //return bitmapScaled; } //bitmapScaled.Recycle(); }
public bool Paste(Template template) { string path = Path + "/" + Move_copy_file.Name; if (Move_copy_file.IsFile) { try { javaIO.InputStream source = new javaIO.FileInputStream(Move_copy_file.AbsolutePath); javaIO.OutputStream dest = new javaIO.FileOutputStream(path); byte[] buffer = new byte[1024]; int length; while ((length = source.Read(buffer)) > 0) { dest.Write(buffer, 0, length); } source.Close(); dest.Close(); } catch (Exception e) { return(false); } if (move) { Delete(template); move = false; } } else if (Move_copy_file.IsDirectory) { new DirectoryInfo(template.Getfile.AbsolutePath).CreateSubdirectory(Move_copy_file.Name); File newDirectory = new File(path); if (newDirectory.Exists()) { } CopyDirectory(template); } template.Getfile = new File(path); Initialization(); Update(); Move_copy_file = null; return(true); }
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) { base.OnActivityResult(requestCode, resultCode, data); if (resultCode == Result.Ok) { byte[] bytes; using (var stream = new Java.IO.FileInputStream(arquivoImagem)) { bytes = new byte[arquivoImagem.Length()]; stream.Read(bytes); } MessagingCenter.Send <byte[]>(bytes, "FotoTirada"); } }
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) { base.OnActivityResult(requestCode, resultCode, data); Java.IO.File diretorio = new Java.IO.File( Android.OS.Environment.GetExternalStoragePublicDirectory( Android.OS.Environment.DirectoryPictures), "Imagens"); var resolucaoAntiga = SizeImagem(arquivoImagem.Path); ResizeImage(arquivoImagem.Path, diretorio.Path, 1500, 1200); //var altura = bitmap.Height; //var largura = bitmap.Width; //var Alterada_a_resolução = new System.Drawing.Size((int)bitmap.GetBitmapInfo().Height, (int)bitmap.GetBitmapInfo().Width); //SE TIRAR A FOTO e confirmar if (resultCode == Result.Ok) { byte[] bytes; //Retorna uma stream onde é possivel ler os dados do arquivo using (var stream = new Java.IO.FileInputStream(arquivoImagem)) { //Convertendo a imagem em um array de bytes para usar o array na troca de mensagens com o projeto c# bytes = new byte[arquivoImagem.Length()]; //transferir pro array de bytes o conteudo do arquivo de imagem //stream le os dados do arquivo stream.Read(bytes); } //Arquivo do tipo array de byte[] //instancia de arquivoImagem //Sobrepoe a imagem original no diretorio //envia a msg para a classe masterviewmodel MessagingCenter.Send <byte[]>(bytes, "FotoTirada"); } }
//TERMINA PROCESAR IMAGENES public static byte[] PathToByte2(string path){ //byte[] pathData=null; Log.Debug ("ImageToByte", "Inicia path to byte"); Log.Debug ("ImageToByte", "Se crea el nuevo file"); var imgFile = new Java.IO.File(path); Log.Debug ("ImageToByte", "Se crea el nuevo stream"); var stream = new Java.IO.FileInputStream(imgFile); Log.Debug ("ImageToByte", "Se Crea el archivo Byte"); var bytes = new byte[imgFile.Length()]; Log.Debug ("ImageToByte", "Se hace el Stream Read"); stream.Read(bytes); stream.Close (); stream.Dispose (); return bytes; }