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(); }
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; }