Hola amigos tengo el siguiente codigo en la pagina .cs
ACLARO: Localmente funciona a la perfeccion , el problema radica cuando es subido al servidor.
Código:
string salida = MapPath(path + contador.ToString() + ".jpg");
Comprimir_Imagenes.ApplyCompressionAndSave(FU_1.PostedFile.FileName.ToString(), salida);
Esto llama a un metodo estatico. El Cual comprime la imagen y la guarda.
Código:
public static class Comprimir_Imagenes
{
public static void ApplyCompressionAndSave(string path_entrada, string path_salida)
{
Bitmap img;
img = new Bitmap(@path_entrada, true);
long compressionValue = 30;
string mimeType = "image/jpeg";
try
{
//create our EncoderParameters object and pass the values to the EncoderParameter class
EncoderParameters parameters = new EncoderParameters(1);
parameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, compressionValue);
ImageCodecInfo codec = GetEncoderInfo(mimeType);
//now verify that the encoder returned from GetEncoderInfo isnt a null value
if (codec != null)
//an encoder was found so now we can save the image with the specified compression value
img.Save(path_salida, codec, parameters);
else
//no encoder was found so throw an exception
throw new Exception("Codec information not found for the mime type specified. Check your values and try again");
}
catch (Exception ex)
{
}
}
public static ImageCodecInfo GetEncoderInfo(string mimeType)
{
//create an array of ImageCodecInfo by using GetImageEncoders()
ImageCodecInfo[] encoders = ImageCodecInfo.GetImageEncoders();
//first loop through all the encoders that were returned from our ImageCodecInfo array
for (int i = 0; i < encoders.Length; ++i)
//now we need to check for a match to the mime type we're providing
//otherwise we return null
if (encoders[i].MimeType.ToLower() == mimeType.ToLower())
return encoders[i];
return null;
}
}
Pero cuando intento grabar me tira el siguiente error..
Código:
Parameter is not valid.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: Parameter is not valid.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[ArgumentException: Parameter is not valid.]
System.Drawing.Bitmap..ctor(String filename, Boolean useIcm) +376065
ClassLibrary.Varios.Comprimir_Imagenes.ApplyCompressionAndSave(String path_entrada, String path_salida) in C:\Nicolas\Mis Documentos\Mis Webs\DiegoCipolatti\ClassLibrary\Varios\Comprimir_Imagen.cs:28
DiegoCipolatti.Administrador.NuevaObra.Grabar_Imagenes(Int32 numero) in C:\Nicolas\Mis Documentos\Mis Webs\DiegoCipolatti\DiegoCipolatti\Administrador\NuevaObra.aspx.cs:154
DiegoCipolatti.Administrador.NuevaObra.Procesar_Imagenes(Int32 numero) in C:\Nicolas\Mis Documentos\Mis Webs\DiegoCipolatti\DiegoCipolatti\Administrador\NuevaObra.aspx.cs:83
DiegoCipolatti.Administrador.NuevaObra.CmdGrabar_Click(Object sender, EventArgs e) in C:\Nicolas\Mis Documentos\Mis Webs\DiegoCipolatti\DiegoCipolatti\Administrador\NuevaObra.aspx.cs:51
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
He googleado un poco pero no he logrado encontrar una respuesta definitiva para este problema.
Muchas gracias de Antemano.
Y si alguno tiene algun metodo o clase que comprima archivos en C# y este seguro que funcione si es tan amable de pasarmela.
saludos.
Nicolas.