private void Redimensiona(Picture foto,int targetW, int targetH, int resolucion, string name, int agregarMascara) { // generamos un memorystream de la imagen origina MemoryStream imagen = new MemoryStream(); foto.imgOriginal.Save(imagen, ImageFormat.Bmp); // salvamos en el memory la imagen original System.Drawing.Image original = System.Drawing.Image.FromStream(imagen); System.Drawing.Image imgPhoto = System.Drawing.Image.FromStream(imagen); // No vamos a permitir que la imagen final sea más grande que la inicial targetH = targetH <= original.Height ? targetH : original.Height; targetW = targetW <= original.Width ? targetW : original.Width; // se genera una foto con la dimension pedida Bitmap bmPhoto = new Bitmap(targetW, targetH, PixelFormat.Format24bppRgb); // No vamos a permitir dar una resolución mayor de la que tiene resolucion = resolucion <= Convert.ToInt32(bmPhoto.HorizontalResolution) ? resolucion : Convert.ToInt32(bmPhoto.HorizontalResolution); resolucion = resolucion <= Convert.ToInt32(bmPhoto.VerticalResolution) ? resolucion : Convert.ToInt32(bmPhoto.VerticalResolution); // se le da la resolucion a la foto creada bmPhoto.SetResolution(resolucion, resolucion); Graphics grPhoto = Graphics.FromImage(bmPhoto); grPhoto.SmoothingMode = SmoothingMode.AntiAlias; grPhoto.InterpolationMode = InterpolationMode.HighQualityBicubic; grPhoto.PixelOffsetMode = PixelOffsetMode.HighQuality; grPhoto.DrawImage(imgPhoto, new Rectangle(0, 0, targetW, targetH), new Rectangle(0, 0, original.Width, original.Height), GraphicsUnit.Pixel); // geenramos un memorystream de la foto MemoryStream mm = new MemoryStream(); bmPhoto.Save(mm, System.Drawing.Imaging.ImageFormat.Jpeg); // aqui colocamos el codigo para agregara mascara enviando la imagen a laa que se debe de tener mascara (mm) //Mezcla(stream, mascara, 300, 75, 10, 10, false, _path, _nombre, titulo); if (agregarMascara == 1) { Stream imagenProcesada = new MemoryStream(); imagenProcesada = addMascara(mm, targetW, targetH, 10, 10, false, foto.titulo); System.Drawing.Image ImagenSave = System.Drawing.Image.FromStream(imagenProcesada); Rectangle rec = new Rectangle(0, 0, ImagenSave.Width, ImagenSave.Height); grPhoto.DrawImage(ImagenSave, rec, rec, GraphicsUnit.Pixel); } bmPhoto.Save(foto.path + "\\" + name); original.Dispose(); imgPhoto.Dispose(); bmPhoto.Dispose(); grPhoto.Dispose(); mm.Dispose(); //foto.imgOriginal.Dispose(); //return mm; }
//--------------- public Picture CrearFoto(string identificador, string nombre, int numFoto, int ancho, int alto, Directorio dir) { Picture foto = new Picture(); foto.path = dir.path; foto.alto = alto; foto.ancho = ancho; foto.principal = true; foto.nombre = nombre; foto.url = dir.url; foto.titulo = ProcesaTitulo(foto.nombre); foto.numFoto = numFoto; foto.imgOriginal = System.Drawing.Image.FromFile(dir.path + nombre); // foto.imgOriginal.Dispose(); return foto; }
public void CreaPaquetes(Picture foto) { // debo crear cuantas fotos= /* [ ancXalt] descripcion del lugar Nombre designado [100x75] para los anuncios patrocinados _100.jpg [140X100] para el home y los listados _140.jpg [300X200] para la foto mediana de la galeria _300.jpg [50X35] para los tmbails de la galeria _50.jpg [60X60] para los tumbails de la carga de fotografias _60.jpg [original] para el zoom _zoom.jpg */ for (int i = 0; i < 6; i++) { int W = int.Parse(foto.tamanios[i].Split(',')[0]); int H = int.Parse(foto.tamanios[i].Split(',')[1]); Redimensiona(foto,W, H, 100, foto.nombre.ToLower().Replace("_original.jpg", "") + foto.nombres[i], foto.Mascara[i]); } foto.imgOriginal.Dispose(); }
public string creaFotos(string identificador, HttpFileCollectionBase FileCollection) { pictureManagerService pictureService = new pictureManagerService(); Directorio dir = new Directorio(); string nameFile = "electronia--" + identificador; string result = ""; if (FileCollection.Count > 0) { dir = new Directorio(); dir = pictureService.CreaDirectorio(identificador); for (int i = 0; i < FileCollection.Count; i++) { if (FileCollection[i].FileName.Length > 0) { pictureService = new pictureManagerService(); Foto new_photo = new Foto(); new_photo.item_id = identificador; new_photo.url_general = dir.url + nameFile; new_photo.path_general = dir.path + nameFile; new_photo = pictureService.postFoto(identificador, new_photo); if (new_photo.num_photo > 0) { Picture pic = new Picture(); string nombre = nameFile + "_" + new_photo.num_photo + "_original.jpg"; FileCollection[i].SaveAs(dir.path + nombre); string contenido = ""; try { pic = pictureService.CrearFoto(identificador, nombre, new_photo.num_photo, 640, 480, dir); pictureService.CreaPaquetes(pic); //string urlfotos = new_photo.url_general; /* contenidoGallery = "{\"icono\":\"" + urlfotos.Replace("_original.", "_50.") + "\",\"individual\":\"" + urlfotos.Replace("_original.", "_300.") + "\",\"zoom\":\"" + urlfotos.Replace("_original.", "_zoom.") + "\"}"; */ List<Foto> lista_photos = new List<Foto>(); lista_photos = pictureService.getFotos(identificador); foreach (var photos in lista_photos) { string urlfotos = photos.url_general; contenido = "{" + "\"name\":\"" + photos.item_id + "_" + photos.num_photo + "_50.jpg\"," + "\"size\":902604," + "\"url\":\"" + urlfotos.Replace("_original.", "_zoom.") + "\"," + "\"thumbnail_url\":\"" + urlfotos.Replace("_original.", "_60.") + "\"," + "\"delete_url\":\"/home/process_picture/" + photos.item_id + "/?option=delete&photo=" + photos.num_photo + "\"," + "\"delete_type\":\"GET\"" + "},"; } if (contenido.Length > 0) { contenido = "[" + contenido + "]"; contenido = contenido.Replace(",]", "]"); } } catch { // cuando no subio la foto } result = contenido; } } } } else { // obtenemos el get para generar el admin de fotos List<Foto> lista_photos = new List<Foto>(); string contenido = ""; lista_photos = pictureService.getFotos(identificador); foreach (var photos in lista_photos) { string urlfotos = photos.url_general; contenido = contenido + "{" + "\"name\":\"" + photos.item_id + "_" + photos.num_photo + "_50.jpg\"," + "\"size\":902604," + "\"url\":\"" + urlfotos.Replace("_original.", "_zoom.") + "\"," + "\"thumbnail_url\":\"" + urlfotos.Replace("_original.", "_60.") + "\"," + "\"delete_url\":\"/home/process_picture/" + photos.item_id + "/?option=delete&photo=" + photos.num_photo + "\"," + "\"delete_type\":\"GET\"" + "},"; } if (contenido.Length > 0) { contenido = "[" + contenido + "]"; contenido = contenido.Replace(",]", "]"); } /* Directorio dir = new Directorio(); dir = pictureService.CreaDirectorio(identificador, anioRegistro, mesRegistro); string ruta = dir.path; Archivo archivoAdmin = new Archivo(); archivoAdmin = pictureService.CrearArchivo(ruta, identificador + "_admin", "json"); string fotos = pictureService.LeerArchivo(archivoAdmin); result = fotos; */ result = contenido; } return result; }
public void eliminarFoto(string path_foto) { string archivoEliminar; Picture pic = new Picture(); for (int i = 0; i < 6; i++) { archivoEliminar = path_foto.ToLower().Replace("_original.jpg", "") + pic.nombres[i]; if (System.IO.File.Exists(archivoEliminar)) { try { System.IO.File.Delete(archivoEliminar); } catch (System.IO.IOException e) { // guardamos un log de por que no se logro la eliminacion } } } archivoEliminar = (path_foto); if (System.IO.File.Exists(path_foto)) { try { System.IO.File.Delete(path_foto); } catch (System.IO.IOException e) { // guardamos un log de por que no se logro la eliminacion } } // por cada nombre hacemos el borrado }