Ver Mensaje Individual
  #106 (permalink)  
Antiguo 15/03/2006, 17:16
Avatar de pempas
pempas
 
Fecha de Ingreso: diciembre-2003
Ubicación: Barcelona
Mensajes: 985
Antigüedad: 20 años, 4 meses
Puntos: 6
Tema: Redimensionar imágenes
Pregunta: ¿Cómo redimensionar imágenes al vuelo?
Respuesta: Para redimensionar imágenes al vuelo hay que crear una página VB.Net y escribir el siguiente código:

Código:
' Initialize objects
Dim objImage, objThumbnail As System.Drawing.Image
Dim strServerPath, strFilename As String
Dim shtWidth, shtHeight, MaxHeight, Coefficient, W, H As Short 
    
' Get image folder path on server - use "\" string if root
strServerPath = Request.ServerVariables("APPL_PHYSICAL_PATH") & "img\"
' Retrieve name of file to resize from query string
strFilename = strServerPath & Request.QueryString("filename")
' Retrieve file, or error.gif if not available
Try
    objImage = objImage.FromFile(strFilename)
Catch
    objImage = objImage.FromFile(strServerPath & "no.jpg")
End Try
' Retrieve width from query string
If Request.QueryString("width") = Nothing Then
    shtWidth = objImage.Width
ElseIf Request.QueryString("width") < 1 Then
    shtWidth = 100
Else
    shtWidth = Request.QueryString("width")
	W = Request.QueryString("width")
End If

'Ahora miramos que no sobrepase el máximo de alto.
If Request.QueryString("Height")<>Nothing Then
	MaxHeight = Request.QueryString("Height")
	If  objImage.Width > shtWidth Then
		shtWidth = objImage.Width / (objImage.Height / MaxHeight)
		shtHeight = objImage.Height / (objImage.Width / shtWidth)
		If shtWidth > W Then
			H = shtHeight
			shtHeight = MaxHeight / (shtWidth / W)
			shtWidth = W / (H / MaxHeight)
		End If
	Else
		shtWidth = objImage.Width
		shtHeight = objImage.Height
	End If
Else
	' Work out a proportionate height from width
	If  objImage.Width > shtWidth Then
		shtHeight = objImage.Height / (objImage.Width / shtWidth)
	Else
		shtWidth = objImage.Width
		shtHeight = objImage.Height
	End If
End If

' Create thumbnail
objThumbnail = objImage.GetThumbnailImage(shtWidth, _
  shtHeight, Nothing, System.IntPtr.Zero)
' Send down to client
Response.ContentType = "image/jpeg"
objThumbnail.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg)
' Tidy up
objImage.Dispose()
objThumbnail.Dispose()
¿Cómo hacemos la llamada a la imagen?:
Para hacer la llamada la realizamos así:

resize.aspx?filename=imagen.jpg&width=640&Height=4 80

Extraído de http://www.developer.com/net/asp/article.php/3098311

Ahora si alguien se anima e indica como incluir una marca de agua a este código ya sería lo mejor...

Última edición por RootK; 24/03/2006 a las 09:58