我想将加载的图片保存到某个目录,但它一直返回无效的导演。这是我正在使用的代码
if (OpenCdb != null)
{
string pics = Path.GetDirectoryName(OpenCdb.FileName);
// Save card image
ImageResizer.SaveImage(CardImg.Image, pics + "\\pics\\" + cardid + ".jpg", 177, 254);
//Save card thumbnail
ImageResizer.SaveImage(CardImg.Image, pics + "\\pics\\thumbnail\\" + cardid + ".jpg", 44, 64);
}
我已经测试了pics
字符串并返回了正确的目录,所以我不知道还能做什么。如果您也需要我,我也可以发布 imageresizer 功能代码,但是代码很多,这就是我没有在问题中添加它的原因。
编辑这里的错误图片
public static void SaveImage(Image image, string savedName, int width = 0, int height = 0)
{
Image originalImage = image;
string filePath = AppDomain.CurrentDomain.BaseDirectory + savedName;
if (width > 0 && height > 0)
{
Image.GetThumbnailImageAbort myCallback =
new Image.GetThumbnailImageAbort(ThumbnailCallback);
Image imageToSave = originalImage.GetThumbnailImage
(width, height, myCallback, IntPtr.Zero);
imageToSave.Save(filePath, System.Drawing.Imaging.ImageFormat.Jpeg);
}
else
{
originalImage.Save(filePath, System.Drawing.Imaging.ImageFormat.Jpeg);
}
}