来自usb相机的文件路径

Ben*_*enB 10 c++ wia vba gdi+

您好我正在使用GDI +进行一些图像处理.我从命令行运行两个参数.原因是从VBA Excel 2007调用程序.从VBA运行打开文件对话框并给出第一个参数.

第一个论点是要处理的原始图像,第二个是保存图像的位置.当两个参数来自带字母的驱动器,即C:时,一切正常.

它不能使用网络文件夹,即\ server\folder.在尝试加载图像之前,我通过将文件夹安装到驱动器盘符来克服这个问题.

当输入图像在USB摄像头上时,我现在遇到问题.相机上文件的文件路径最终为COMPUTER\Canon\DCIM\image.jpg.Windows没有将相机安装到字母驱动器上,因此它无法正常工作.

在尝试加载图像之前,我添加了额外的'\',以便它们都是双\.

我根本不确定如何让它发挥作用并且全神贯注.谢谢.

int main(int argc, char* argv[])
{
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR           gdiplusToken;

// INITIALIZE GDI+
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

wchar_t tin[200] = L"";
wchar_t in[200] = L"";
wchar_t out[200] = L"";
wchar_t tout[200] = L"";

NETRESOURCE nr;
DWORD dwRetVal;

nr.dwType = RESOURCETYPE_DISK;
nr.lpLocalName = "M:";
nr.lpRemoteName = "\\\\server\\folder";
nr.lpProvider = NULL;
// Map the mugshots folder
dwRetVal = WNetAddConnection2(&nr, NULL, NULL, CONNECT_TEMPORARY);

// Convert to a wchar_t* from command line argument
size_t origsize = strlen(argv[1]) + 1;
mbstowcs( tin, argv[1], origsize);

//Add an extra \ for directory
int j = 0;
for (int i = 0 ; i < int(origsize) ; i++)
{
    if(tin[i] == '\\')
    {
        in[j] = '\\';
        j++;
        in[j] = '\\';
        j++;
    }
    else
    {
        in[j] = tin[i];
        j++;
    }
}

// Convert to a wchar_t* from command line argument
origsize = strlen(argv[2]) + 1;
mbstowcs(tout, argv[2], origsize);
//Add an extra \ for directory

out[0] = 'M';
out[1] = ':';
out[2] = '\\';
out[3] = '\\';
j = 4;
for (int i = 0 ; i < int(origsize) ; i++)
{
    if(tout[i] == '\\')
    {
        out[j] = '\\';
        j++;
        out[j] = '\\';
        j++;
    }
    else
    {
        out[j] = tout[i];
        j++;
    }
}

Bitmap b(in);

Process image

CLSID pngClsid;
GetEncoderClsid(L"image/jpeg", &pngClsid);
image2->Save(out, &pngClsid, NULL);

return 0;
}
Run Code Online (Sandbox Code Playgroud)

ker*_*ert 0

您需要研究 shell 如何处理特殊路径,一个好的开始是: http: //msdn.microsoft.com/en-us/library/bb773559%28v=vs.85%29.aspx

对于您正在做的很多事情,您应该使用 PathCanonicalize() 或类似的东西。不确定这是否对您使用相机有帮助,您可能需要直接访问图像采集 API 以从某些相机中获取文件。