/// <summary> /// CAMBIAR LA IMAGEN DE PERFIL DESDE LA CAMARA /// </summary> /// <param name="requestCode"></param> /// <param name="resultCode"></param> /// <param name="data"></param> protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data) { if (data != null) { base.OnActivityResult(requestCode, resultCode, data); Bitmap bitmap = (Bitmap)data.Extras.Get("data"); Img.SetImageBitmap(bitmap); //convertimos a Byte para luego almacenarlo en el servidor using (var stream = new MemoryStream()) { bitmap.Compress(Bitmap.CompressFormat.Png, 0, stream); bitmapData = stream.ToArray(); } //ALMACENAR LA FOTO DEL CLIENTE var foto = Service.ImageChange(Service.CustomerId, bitmapData); if (foto.band) { Toast.MakeText(this, foto.message, ToastLength.Long).Show(); } else { Toast.MakeText(this, foto.message, ToastLength.Long).Show(); } } }
/// <summary> /// CAMBIAR LA IMAGEN DE PERFIL CON GALERIA /// </summary> async void UploadPhoto() { await CrossMedia.Current.Initialize(); if (!CrossMedia.Current.IsPickPhotoSupported) { Toast.MakeText(this, "Upload not supported on this device", ToastLength.Short).Show(); return; } var file = await CrossMedia.Current.PickPhotoAsync(new Plugin.Media.Abstractions.PickMediaOptions { PhotoSize = Plugin.Media.Abstractions.PhotoSize.Full, CompressionQuality = 40 }); if (file != null) { // Convert file to byre array, to bitmap and set it to our ImageView byte[] imageArray = System.IO.File.ReadAllBytes(file.Path); Bitmap bitmap = BitmapFactory.DecodeByteArray(imageArray, 0, imageArray.Length); Img.SetImageBitmap(bitmap); //convertimos a Byte para luego almacenarlo en el servidor using (var stream = new MemoryStream()) { bitmap.Compress(Bitmap.CompressFormat.Png, 0, stream); bitmapData = stream.ToArray(); } //ALMACENAR LA FOTO DEL CLIENTE var foto = Service.ImageChange(Service.CustomerId, bitmapData); if (foto.band) { Toast.MakeText(this, foto.message, ToastLength.Long).Show(); } else { Toast.MakeText(this, foto.message, ToastLength.Long).Show(); } } }