Foros del Web » Programación para mayores de 30 ;) » .NET »

Imagenes con transparencia ? ayuda por favor !!

Estas en el tema de Imagenes con transparencia ? ayuda por favor !! en el foro de .NET en Foros del Web. Hola amigos, les cuento que tengo una lista hecha en asp la cual va mostrando fotos, pero como las fotos a veces son muy grandes ...
  #1 (permalink)  
Antiguo 14/08/2007, 07:33
 
Fecha de Ingreso: diciembre-2004
Mensajes: 139
Antigüedad: 19 años, 4 meses
Puntos: 1
Imagenes con transparencia ? ayuda por favor !!

Hola amigos, les cuento que tengo una lista hecha en asp la cual va mostrando fotos, pero como las fotos a veces son muy grandes y pesadas tarda mucho en cargarlas, entonces encontre un archivo en .net que me ayudo muchisimo, el cual analiza el link a la imagen y hace el rezise en el acto. Anda perfecto.
El problema es que no me respeta las transparencias de los gif y los png !!!

Yo al codigo lo llamo asi desde la lista:

Código:
<img src="thumbnail.aspx?ForceAspect=False&Width=<%=Wlogo%>&Height=<%=Hlogo%>&Image=<%=rs2("logo")%>">
Y el codigo del archivo en cuestion es:

Código:
<%@ Page Language="C#" ContentType="text/html" ResponseEncoding="iso-8859-1" %>
<script language="C#" runat="server">
void Page_Load(Object sender, EventArgs e)
{
	try{
		Response.Cache.VaryByParams["Image;Width;Height;ForceAspect"] = true;
		Response.ContentType = "image/jpeg";
		System.Collections.Hashtable imageOutputFormatsTable = new System.Collections.Hashtable();
		imageOutputFormatsTable.Add(System.Drawing.Imaging.ImageFormat.Gif.Guid, System.Drawing.Imaging.ImageFormat.Gif);
		imageOutputFormatsTable.Add(System.Drawing.Imaging.ImageFormat.Jpeg.Guid, System.Drawing.Imaging.ImageFormat.Jpeg);
		imageOutputFormatsTable.Add(System.Drawing.Imaging.ImageFormat.Bmp.Guid, System.Drawing.Imaging.ImageFormat.Gif);
		imageOutputFormatsTable.Add(System.Drawing.Imaging.ImageFormat.Tiff.Guid, System.Drawing.Imaging.ImageFormat.Jpeg);
		imageOutputFormatsTable.Add(System.Drawing.Imaging.ImageFormat.Png.Guid, System.Drawing.Imaging.ImageFormat.Jpeg);
	
		string imageLocation;
		bool forceaspect = true;
		int newHeight;
		int newWidth;
		int reqHeight = 100;
		int reqWidth = 100;
		int origHeight;
		int origWidth;
		
		imageLocation = Server.MapPath(Request.QueryString["Image"]);
		if (Request.QueryString["Height"] != null){
			reqHeight = Convert.ToInt32(Request.QueryString["Height"]);
		}
		if (Request.QueryString["ForceAspect"] != null){
			forceaspect = Convert.ToBoolean(Request.QueryString["ForceAspect"]);
		}
		if(Request.QueryString["Width"] != null){
			reqWidth = Convert.ToInt32(Request.QueryString["Width"]);
		}
		if (Request.QueryString["ForceAspect"] == "true"){
			forceaspect = true;
		}
		
		System.Drawing.Bitmap origBitmap = new System.Drawing.Bitmap(imageLocation);
		origHeight = origBitmap.Height;
		origWidth = origBitmap.Width;
		
		if (forceaspect){
			//Force Aspect Change
			newHeight = reqHeight;
			newWidth = reqWidth;
		}		
		else{ 
			//Landscape
			newWidth = reqWidth;
			newHeight = (int)(((double)origBitmap.Height / (double)origBitmap.Width) * reqWidth);
		}		
		
		System.Drawing.Bitmap outputImage = new System.Drawing.Bitmap(origBitmap, newWidth, newHeight);
		//outputImage.SetResolution(24, 24); //use this line for lower resolution thumbnails
		outputImage.SetResolution(72, 72); 
					
		//outputImage.InterpolationMode = InterpolationMode.HighQualityBicubic;
		System.Drawing.Imaging.ImageFormat outputFormat = (System.Drawing.Imaging.ImageFormat)imageOutputFormatsTable[origBitmap.RawFormat.Guid];
		
		outputImage.Save(Response.OutputStream, outputFormat);
		outputImage.Dispose();
		origBitmap.Dispose();
	}
	catch (Exception ex){
		//log error so we may know the problem. you need to have write permits, of course on log path			
		System.IO.StreamWriter sw=null;
		try{
			sw=new System.IO.StreamWriter(Server.MapPath("error.txt"),true);
			sw.WriteLine("Error : " + ex.Message + " processing " + Request.QueryString["Image"]);
		}	 
		catch{}		
		finally{sw.Close();}
		//now display the error image
		Response.Redirect("thumberror.gif");
	}
}
</script>
Alguien que sepa asp.net me puede modificar el codigo para que respete porlomenos los jpg y los gif con transparencia ??????
  #2 (permalink)  
Antiguo 16/08/2007, 11:45
 
Fecha de Ingreso: diciembre-2004
Mensajes: 139
Antigüedad: 19 años, 4 meses
Puntos: 1
Re: Imagenes con transparencia ? ayuda por favor !!

Nadie sabe ?
  #3 (permalink)  
Antiguo 19/09/2007, 07:28
 
Fecha de Ingreso: diciembre-2004
Mensajes: 139
Antigüedad: 19 años, 4 meses
Puntos: 1
Re: Imagenes con transparencia ? ayuda por favor !!

No hay nadie que sepa como solucionar el tema el transparencias ? seria muy util para todos
  #4 (permalink)  
Antiguo 09/11/2007, 03:22
MK2
 
Fecha de Ingreso: enero-2007
Mensajes: 48
Antigüedad: 17 años, 3 meses
Puntos: 0
Re: Imagenes con transparencia ? ayuda por favor !!

Estas creando un System.Drawing.Bitmap,... has comprobado que esta función acepte transparencias? Cuando creas una imágen nueva es posible que no lo acepte. Prueba son un Image, pasa tu imágen a byte[] y juega con eso.
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 23:51.