I have a program that saves images, but when I debug it I get this error:
The given path's format is not supported.
I want to know why it is not supported, and how to fix this issue. Thanks in advance
My Code
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);
Edit
I have added the code, and it compiles correctly, but the file never saves. Here's the code:
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);
}
Edit
I have added all of the below code, but I still get the The given path's format is not supported.
error. Thanks again.
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
}
}
}