Foros del Web » Programando para Internet » ASPX (.net) »

validar longitudes de imagenes antes de upload

Estas en el tema de validar longitudes de imagenes antes de upload en el foro de ASPX (.net) en Foros del Web. en mi app web asp.net tengo q validar el height y width de una imagen antes de subirla al servidor , lo trate de hacer ...
  #1 (permalink)  
Antiguo 25/01/2006, 12:41
Avatar de jocks  
Fecha de Ingreso: marzo-2004
Mensajes: 174
Antigüedad: 20 años, 1 mes
Puntos: 0
validar longitudes de imagenes antes de upload

en mi app web asp.net tengo q validar el height y width de una imagen antes de subirla al servidor , lo trate de hacer , pero como capturo la imagen que ha sido seleccionada en el control field (este control es el tipico html que se usa para subir imagenes).
La idea es validar las longitudes de la imagen y si excede a los valores que tengo ya definidos hacer un resize de la imagen si perder el aspcet ratio.
Encontre varios ejemplos pero trabajan con imagenes que ya han sido subidas, mi problemas es al momento que recien se sube la imagen, se que tengo q instanciar la clace IMAGE , y usar su metodo fromfile(string) , pero cuando le paso el string d la ruta d la imagen , me vota un error .
Alguna ayuda por favor
__________________
JUST DO IT!!!
nunk hay una segunda oportunidad para una primera buena impresion...
  #2 (permalink)  
Antiguo 25/01/2006, 13:19
Avatar de xknown  
Fecha de Ingreso: diciembre-2004
Ubicación: Cusco - Perú
Mensajes: 2.248
Antigüedad: 19 años, 4 meses
Puntos: 7
No puedes validar el tamaño sin antes subir la imágen, en todo caso, sería mejor que nos muestres que error te manda.

Saludos
__________________
Alex Concha
Buayacorp - Programación y Diseño
  #3 (permalink)  
Antiguo 25/01/2006, 13:49
Avatar de jocks  
Fecha de Ingreso: marzo-2004
Mensajes: 174
Antigüedad: 20 años, 1 mes
Puntos: 0
validar longitudes de imagen

no hay forma de validar las longitudes de la imagen que el cliente trata de subir al servidor , pero antes de hacer el upload??
__________________
JUST DO IT!!!
nunk hay una segunda oportunidad para una primera buena impresion...
  #4 (permalink)  
Antiguo 25/01/2006, 14:07
Avatar de xknown  
Fecha de Ingreso: diciembre-2004
Ubicación: Cusco - Perú
Mensajes: 2.248
Antigüedad: 19 años, 4 meses
Puntos: 7
NO.

Saludos
__________________
Alex Concha
Buayacorp - Programación y Diseño
  #5 (permalink)  
Antiguo 25/01/2006, 14:29
Avatar de Mickel  
Fecha de Ingreso: mayo-2002
Ubicación: Lima, Peru
Mensajes: 4.619
Antigüedad: 22 años
Puntos: 7
No. Si es para ti, olvida esa idea. Y si es para un cliente, preguntale en que pagina si lo ha visto...
__________________
No tengo firma ahora... :(
  #6 (permalink)  
Antiguo 25/01/2006, 17:52
Avatar de jocks  
Fecha de Ingreso: marzo-2004
Mensajes: 174
Antigüedad: 20 años, 1 mes
Puntos: 0
dimensionar imagen al hacer upload sin perder el aspect ratio

de acuerdo, en todo caso conocen algun buen ejemplo de codigo donde se suba al servidor una imagen de cualquier dimension(width y heigth) y por codigo , dinamicamente adecue sus dimensiones a unas que yo tengo ya establecidas o en todo caso solo reducir proporcionalmente sus dimensiones pero sin perder el aspect ratio de la foto.

Es decir ; si se sube una imagen de 800x600, reducirla a 80x60 por ejemplo sin perder el aspcet ratio.

Saludos
__________________
JUST DO IT!!!
nunk hay una segunda oportunidad para una primera buena impresion...
  #7 (permalink)  
Antiguo 26/01/2006, 17:20
Avatar de jocks  
Fecha de Ingreso: marzo-2004
Mensajes: 174
Antigüedad: 20 años, 1 mes
Puntos: 0
aspect ratio??

alguien me puede aclarar a que se refieren con hacer un resize de la imagen sin perder el aspect ratio??
__________________
JUST DO IT!!!
nunk hay una segunda oportunidad para una primera buena impresion...
  #8 (permalink)  
Antiguo 26/01/2006, 18:07
Avatar de xknown  
Fecha de Ingreso: diciembre-2004
Ubicación: Cusco - Perú
Mensajes: 2.248
Antigüedad: 19 años, 4 meses
Puntos: 7
Cita:
Iniciado por jocks
alguien me puede aclarar a que se refieren con hacer un resize de la imagen sin perder el aspect ratio??
, pareciera que son 2 personas diferentes con un mismo usuario...

Sugiero que uses(n?) un buscador, tanto para buscar el ejemplo, como para encontrar que significa aspect ratio.

Saludos
__________________
Alex Concha
Buayacorp - Programación y Diseño
  #9 (permalink)  
Antiguo 27/01/2006, 22:07
Avatar de jocks  
Fecha de Ingreso: marzo-2004
Mensajes: 174
Antigüedad: 20 años, 1 mes
Puntos: 0
codigo para resize images

weno en tanto investigar encontre esta clace en C# q me ayuda a trabajar el resize de mis images sin perder el aspect ratio.
aki lo comparto si a alguien se le presenta lo mismo q a mi:

using System;
using System.Drawing;
using System.IO;
namespace ImageHelper
{
public class ImageResize
{
private double m_width, m_height;
private bool m_use_aspect = true;
private bool m_use_percentage = false;
private string m_image_path;
private Image m_src_image, m_dst_image;
private ImageResize m_cache;
private Graphics m_graphics;
public string File
{
get { return m_image_path; }
set { m_image_path = value; }
}
public Image Image
{
get { return m_src_image; }
set { m_src_image = value; }
}
public bool PreserveAspectRatio
{
get { return m_use_aspect; }
set { m_use_aspect = value; }
}
public bool UsePercentages
{
get { return m_use_percentage; }
set { m_use_percentage = value; }
}
public double Width
{
get { return m_width; }
set { m_width = value; }
}
public double Height
{
get { return m_height; }
set { m_height = value; }
}
protected virtual bool IsSameSrcImage(ImageResize other)
{
if (other != null)
{
return (File == other.File
&& Image == other.Image);
}

return false;
}
protected virtual bool IsSameDstImage(ImageResize other)
{
if (other != null)
{
return (Width == other.Width
&& Height == other.Height
&& UsePercentages == other.UsePercentages
&& PreserveAspectRatio == other.PreserveAspectRatio);
}

return false;
}
public virtual Image GetThumbnail()
{
// Flag whether a new image is required
bool recalculate = false;
double new_width = Width;
double new_height = Height;

// Is there a cached source image available? If not,
// load the image if a filename was specified; otherwise
// use the image in the Image property
if (!IsSameSrcImage(m_cache))
{
if (m_image_path.Length > 0)
{
// Load via stream rather than Image.FromFile to release the file
// handle immediately
if (m_src_image != null)
m_src_image.Dispose();

// Wrap the FileStream in a "using" directive, to ensure the handle
// gets closed when the object goes out of scope
using(Stream stream = new FileStream(m_image_path, FileMode.Open))
m_src_image = Image.FromStream(stream);

recalculate = true;
}
}

// Check whether the required destination image properties have
// changed
if (!IsSameDstImage(m_cache))
{
// Yes, so we need to recalculate.
// If you opted to specify width and height as percentages of the original
// image's width and height, compute these now
if (UsePercentages)
{
if (Width != 0)
{
new_width = (double) m_src_image.Width * Width / 100;

if (PreserveAspectRatio)
{
new_height = new_width * m_src_image.Height / (double) m_src_image.Width;
}
}

if (Height != 0)
{
new_height = (double) m_src_image.Height * Height / 100;

if (PreserveAspectRatio)
{
new_width = new_height * m_src_image.Width / (double) m_src_image.Height;
}
}
}
else
{
// If you specified an aspect ratio and absolute width or height, then calculate this
// now; if you accidentally specified both a width and height, ignore the
// PreserveAspectRatio flag
if (PreserveAspectRatio)
{
if (Width != 0 && Height == 0)
{
new_height = (Width / (double) m_src_image.Width) * m_src_image.Height;
}
else if (Height != 0 && Width == 0)
{
new_width = (Height / (double) m_src_image.Height) * m_src_image.Width;
}
}
}
recalculate = true;
}
if (recalculate)
{
// Calculate the new image
if (m_dst_image != null)
{
m_dst_image.Dispose();
m_graphics.Dispose();
}
Bitmap bitmap = new Bitmap((int)new_width, (int)new_height, m_src_image.PixelFormat);
m_graphics = Graphics.FromImage(bitmap);
m_graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality ;
m_graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQua lityBicubic;

m_graphics.DrawImage(m_src_image, 0, 0, bitmap.Width, bitmap.Height);
m_dst_image = bitmap;
// Cache the image and its associated settings
m_cache = this.MemberwiseClone() as ImageResize;
}

return m_dst_image;
}
~ImageResize()
{
// Free resources
if (m_dst_image != null)
{
m_dst_image.Dispose();
m_graphics.Dispose();
}
if (m_src_image != null)
m_src_image.Dispose();
}
}
}


Saludos
__________________
JUST DO IT!!!
nunk hay una segunda oportunidad para una primera buena impresion...
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 09:34.