我有一个保存图像的程序,但是当我调试它时,我得到了这个错误:
不支持给定路径的格式。
我想知道为什么不支持它,以及如何解决这个问题。提前致谢
我的代码
BitmapSource image = BitmapSource.Create(colorFrame.Width, colorFrame.Height,
96, 96, PixelFormats.Bgr32, null, pixels, stride);
ImageFormat format = ImageFormat.Jpeg;
string file_name = "C:\\Kinected\\Images\\Kinect" + bb1 + ".jpg";
image.Save(file_name, format);
编辑
我已经添加了代码,它可以正确编译,但文件永远不会保存。这是代码:
string mypath = System.IO.Path.Combine(@"C:\", "Kinected", "Images");
if (!Directory.Exists(mypath))
{
Directory.CreateDirectory(mypath);
file_name = System.IO.Path.Combine(mypath, "Kinect 1" + bb1 + ".jpeg");
}
if (file_name == null)
{
return;
}
if (!Directory.Exists(file_name))
{
Directory.CreateDirectory(file_name);
}
编辑
我已经添加了以下所有代码,但仍然The given path's format is not supported.
出现错误。再次感谢。
BitmapSource image = BitmapSource.Create(
colorFrame.Width, colorFrame.Height, 96, 96, PixelFormats.Bgr32, null, pixels, stride);
totalFrames = colorFrame.FrameNumber;
ImageFormat format = ImageFormat.Jpeg;
if (PersonDetected == true)
{
if (!Directory.Exists(mypath))
{
Directory.CreateDirectory(mypath);
file_name = "C:\\Kinected\\Images\\Kinect 1 " + bb1 + ".jpeg";
}
if (file_name == null || mypath == null || image == null)
{
if (mypath == null)
{
mypath = System.IO.Path.Combine("D:/", "Kinected", "Images");
if (!Directory.Exists(mypath))
{
Directory.CreateDirectory(mypath);
}
}
if (file_name == null)
{
file_name = "D:\\Kinected\\Images\\Kinect " + bb1 + ".jpeg";
}
if (image == null)
{
image = BitmapSource.Create(
colorFrame.Width, colorFrame.Height, 96, 96, PixelFormats.Bgr32, null, pixels, stride);
}
}
if (totalFrames % 10 == 0)
{
if (file_name != null && image != null && format != null)
{
image.Save(file_name, format);//where I get the error
}
}
}