EventHandler ClickCamera() { return((sender, e) => { TakePicture(this, (obj) => { var photo = obj.ValueForKey(new NSString("UIImagePickerControllerOriginalImage")) as UIImage; var ids = new List <string>(); var photosUrl = new List <string>(); photo = photo.Scale(new CGSize(photo.Size.Width * 0.2, photo.Size.Height * 0.2)); using (var imgData = photo.AsJPEG(0.7f)) { var container = new ContainerRestCon(); foreach (var id in modelPCL.infoUsuario) { ids.Add(id.ID); photosUrl.Add(container.GravarArquivo(imgData.AsStream(), id.ID + ".JPEG")); } } InvokeOnMainThread(delegate { modelPCL.dbPdvs.InsertFotoProfile(photosUrl, ids); modelPCL.infoUsuario = modelPCL.dbPdvs.GetUserInfoLogged(); profileAvatar.SetImage(GetBitMap(modelPCL.infoUsuario[0].AVATAR), UIControlState.Normal); }); }); }); }
/// <summary> /// Insere fotos que sobrescrevem a outra. /// </summary> /// <returns>url da foto</returns> /// <param name="nameFile">Nome do Arquivo.</param> internal List <string> PerformOnActivity(List <string> nameFile) { var container = new ContainerRestCon(); var contentUri = Android.Net.Uri.FromFile(fotoDir); var foto = LoadAndResizeBitmap(contentUri.Path); var ei = new ExifInterface(contentUri.Path); var orientation = ei.GetAttributeInt(ExifInterface.TagOrientation, (int)Orientation.Undefined); switch (orientation) { case (int)Orientation.Rotate90: foto = RotateImage(foto, 90); break; case (int)Orientation.Rotate180: foto = RotateImage(foto, 180); break; case (int)Orientation.Rotate270: foto = RotateImage(foto, 270); break; case (int)Orientation.Normal: break; } using (var stream = new MemoryStream()) { var urls = new List <string>(); foto.Compress(Bitmap.CompressFormat.Jpeg, 70, stream); foreach (var item in nameFile) { urls.Add(container.GravarArquivo(stream, item + "." + Bitmap.CompressFormat.Jpeg)); } fotoDir.Delete(); foto = null; GC.Collect(); return(urls); } }
/// <summary> /// Insere fotos que nao sobrescrevem a outra ( usa o timeStamp para diferenciar ) /// </summary> /// <returns>url da foto</returns> /// <param name="nameFile">Nome do arquivo</param> /// <param name="timeStamp">Data atualizada</param> internal string PerformOnActivity(string nameFile, DateTime timeStamp) { var container = new ContainerRestCon(); var contentUri = Android.Net.Uri.FromFile(fotoDir); var foto = LoadAndResizeBitmap(contentUri.Path); var ei = new ExifInterface(contentUri.Path); var orientation = ei.GetAttributeInt(ExifInterface.TagOrientation, (int)Orientation.Undefined); switch (orientation) { case (int)Orientation.Rotate90: foto = RotateImage(foto, 90); break; case (int)Orientation.Rotate180: foto = RotateImage(foto, 180); break; case (int)Orientation.Rotate270: foto = RotateImage(foto, 270); break; case (int)Orientation.Normal: break; } using (var stream = new MemoryStream()) { foto.Compress(Bitmap.CompressFormat.Jpeg, 70, stream); var url = container.GravarArquivo(stream, nameFile + "_TIMESTAMP_" + timeStamp.Ticks + "." + Bitmap.CompressFormat.Jpeg); fotoDir.Delete(); foto = null; GC.Collect(); return(url); } }
void TakePhoto(string typePhoto) { Camera.TakePicture(this, (obj) => { var photo = obj.ValueForKey(new NSString("UIImagePickerControllerOriginalImage")) as UIImage; photo = photo.Scale(new CoreGraphics.CGSize(photo.Size.Width * 0.2, photo.Size.Height * 0.2)); using (var imgData = photo.AsJPEG(0.7f)) { var container = new ContainerRestCon(); var newName_Foto = "VISITAS_" + IdPdv; if (!string.IsNullOrEmpty(IdProduto)) { newName_Foto += "_PRODUTO_" + IdProduto; } newName_Foto += "_TIPO_" + typePhoto + "_TIMESTAMP_" + DateTime.Now.Ticks + ".JPEG"; newName_Foto = newName_Foto.Replace(" ", "-"); container.GravarArquivo(imgData.AsStream(), newName_Foto); #if !DEBUG HockeyApp.MetricsManager.TrackEvent("FotoSucesso"); #endif } }); }
public string DownloadImage(string name, string folder) { try { if (clientAzureStorage != null) { var container = clientAzureStorage.GetContainerReference(folder.Substring(0, folder.IndexOf(".", StringComparison.CurrentCulture))); var blob = container.GetBlockBlobReference(name); using (Stream image = new MemoryStream()) { blob.DownloadToStreamAsync(image).Wait(); if (image.Length > 0) { return(containerLocal.GravarArquivo(image, name)); } throw new Container404Exception(); } } throw new UnauthorizedException(); } catch (Exception e) { if (e.InnerException.Message.Contains("The specified blob does not exist.")) { return(null); } if (e.InnerException.Message.Contains("Server failed to authenticate the request.")) { throw new UnauthorizedException(); } if (e.InnerException.Message.Contains("The specified container does not exist.")) { throw new Container404Exception(); } } return(null); }