开发者

File path from a usb camera

开发者 https://www.devze.com 2023-03-14 06:11 出处:网络
Hello I am using GDI+ to do some image processing.I am having it run from the command line with two arguments.The reason for this is the program is being called from VBA Excel 2007.A Open file dialog

Hello I am using GDI+ to do some image processing. I am having it run from the command line with two arguments. The reason for this is the program is being called from VBA Excel 2007. A Open file dialog is run from VBA and gives the first argument.

The first arguement is the original image to be processed and the second is where to save the image. Everything works just fine when the two arguments come from a drive with a letter, i.e. C:.

It was not working with network folders, i.e. \server\folder. I overcame this by mounting the folder to a drive letter before trying to load the image.

I have a problem now when the incoming image is on a usb camera. The file path of the file on the camera ends up being COMPUTER\Canon\DCIM\image.jpg. Windows is not mounting the camera to a lettered drive so it is not working correctly for me.

Before trying to load the image I add and extra '\' so that they are all double \.

I am not sure at all how to get this to work and have looked all over. Thanks.

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;
// Ma开发者_如何学Gop 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;
}


Please take a look at the sample: GetImage Sample: Demonstrates the Windows Image Acquisition API:

The sample application has a single command on its File menu, named From scanner or camera. When a WIA device (or a device emulator) is attached, the menu item becomes enabled. When the user selects the menu command, the sample will sequentially display the WIA Device Selection dialog box, Image Selection dialog box, and Image Transfer dialog box. The device and image selection dialog boxes are the common dialog boxes supplied by the system, and the transfer dialog box is implemented in this sample. Finally, the sample will display the transferred image(s) in child window(s).

Hope this helps.


You need to look into how shell handles the special paths, a good start is here: http://msdn.microsoft.com/en-us/library/bb773559%28v=vs.85%29.aspx

For a lot of what you are doing, you should be using PathCanonicalize() or something along these lines. Unsure if this helps you with your camera, you may need to access image acquisition APIs directly to get files out of some cameras.

0

精彩评论

暂无评论...
验证码 换一张
取 消