来自usb相机的文件路径

时间:2011-06-18 07:36:52

标签: c++ vba gdi+ wia

您好我正在使用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;
}

2 个答案:

答案 0 :(得分:1)

请查看示例:GetImage Sample: Demonstrates the Windows Image Acquisition API

  

示例应用程序在其File菜单上有一个名为的命令   从扫描仪或相机。当WIA设备(或设备模拟器)是   附加,菜单项变为启用。当用户选择时   菜单命令,样本将依次显示WIA设备   选择对话框,图像选择对话框和图像传输   对话框。设备和图像选择对话框是常见的   系统提供的对话框,以及传输对话框   在此示例中实现。最后,样本将显示   在子窗口中传输图像。

希望这有帮助。

答案 1 :(得分:0)

您需要了解shell如何处理特殊路径,这里有一个好的开头: http://msdn.microsoft.com/en-us/library/bb773559%28v=vs.85%29.aspx

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