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