2011-02-03 9 views
0
public void SaveJpeg(string path, Image image, int quality) 
{ 
    //ensure the quality is within the correct range 
    if ((quality < 0) || (quality > 100)) 
    { 
     //create the error message 
     string error = string.Format("Jpeg image quality must be between 0 and 100, with 100 being the highest quality. A value of {0} was specified.", quality); 
     //throw a helpful exception 
     throw new ArgumentOutOfRangeException(error); 
    } 

    //create an encoder parameter for the image quality 
    EncoderParameter qualityParam = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, quality); 
    //get the jpeg codec 
    ImageCodecInfo jpegCodec = GetEncoderInfo("image/jpeg"); 

    //create a collection of all parameters that we will pass to the encoder 
    EncoderParameters encoderParams = new EncoderParameters(1); 
    //set the quality parameter for the codec 
    encoderParams.Param[0] = qualityParam; 
    //save the image using the codec and the parameters 
    image.Save(path, jpegCodec, encoderParams); 
} 

この行は、実際に問題がある:image.Save(path, jpegCodec, encoderParams);保存画像経路問題

私はパス= "C:/PathToMyProject/imagename.jpg"、その後の保存作品を設定した場合、私は、相対パスを使用する場合、私はエラーを取得

A GDI +で一般的なエラーが発生しました。

私も試してみました

Server.MapPath(path)しかし、誰の助け。

私の質問は、アップロードフォルダへの相対パスを設定する方法ですか?物理パスに

Request.PhysicalApplicationPath + "/images/Image1.jpg"; 
+0

はこのASP.NETですか? – BrokenGlass

+0

エラーが発生したときの「パス」の値は何ですか? –

+0

これはすでにディスク上にあったファイルですか(つまり、ファイルの場合は以前のバージョンを上書きしていますか)。 –

答えて

2

地図指定された仮想パス:

+0

これはそれです...ありがとう! –

0

次のようなものを使用することができます。

Path.Combine(Server.MapPath("~/images/store"), imageName);