保存图像 - 路径问题 [英] Saving image - path problem
本文介绍了保存图像 - 路径问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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);
This line is actually a problem: image.Save(path, jpegCodec, encoderParams);
如果我设置path = C:/PathToMyProject/imagename.jpg
然后保存工作,但如果我使用相对路径然后我得到错误
If I set path = "C:/PathToMyProject/imagename.jpg"
then saving works, but if I use relative path then I get error
GDI +中发生一般错误。
A generic error occurred in GDI+.
我也尝试过: Server.MapPath(路径)
但没有帮助。
I also tried: Server.MapPath(path)
but no help.
我的问题是如何设置上传文件夹的相对路径?
My question is how to set relative path to upload folder?
推荐答案
将指定的虚拟路径映射到物理路径。
Maps the specified virtual path to a physical path.
Path.Combine(Server.MapPath(〜/ images / store) ,imageName);
这篇关于保存图像 - 路径问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文