英文:
Get camera model from picture file in c++
问题
I hope this isn't a duplicate, but I wasn't able to find something similar.
I was wondering how I could get the picture details for a specific file in windows.
When searching for ways to do this, I was mainly pointed towards the following code, but I'm not sure how to use it/if it's the best option:
std::string ImageProcessor::GetCameraType(std::string filePath)
{
WIN32_FILE_ATTRIBUTE_DATA fInfo;
auto stemp = std::wstring(filePath.begin(), filePath.end());
GetFileAttributesEx(stemp.c_str(), GetFileExInfoStandard, &fInfo);
//PrintFileAttributes(fInfo.dwFileAttributes);
}
Can I even use these file attributes to get those custom camera details? Or do I need to go about it in another way? (FYI, the picture is a CR2 file)
I'm new to c++ so all help would be helpful!
英文:
I hope this isn't a duplicate, but I wasn't able to find something similar.
I was wondering how I could get the picture details for a specific file in windows.
When searching for ways to do this, I was mainly pointed towards the following code, but I'm not sure how to use it/if it's the best option:
std::string ImageProcessor::GetCameraType(std::string filePath)
{
WIN32_FILE_ATTRIBUTE_DATA fInfo;
auto stemp = std::wstring(filePath.begin(), filePath.end());
GetFileAttributesEx(stemp.c_str(), GetFileExInfoStandard, &fInfo);
//PrintFileAttributes(fInfo.dwFileAttributes);
}
Can I even use these file attributes to get those custom camera details? Or do I need to go about it in another way? (FIY, the picture is a CR2 file)
I'm new to c++ so all help would be helpfull!
答案1
得分: 2
有多种方法可以实现这一点。最简单的方法是使用Shell API并查询System.Photo.CameraModel属性,类似于以下内容:
#include <windows.h>
#include <shobjidl_core.h>
#include <propkey.h>
#include <stdio.h>;
int main()
{
CoInitialize(NULL);
IShellItem2* item;
if (SUCCEEDED(SHCreateItemFromParsingName(L"c:\\path\\photo.jpg", NULL, IID_PPV_ARGS(&item)))
{
LPWSTR str;
if (SUCCEEDED(item->GetString(PKEY_Photo_CameraModel, &str)))
{
wprintf(L"Model: %s\n", str);
CoTaskMemFree(str);
}
item->Release();
}
CoUninitialize();
return 0;
}
英文:
There are multiple ways to do this. The most simple is to use the Shell API and query for the System.Photo.CameraModel property, something like this:
#include <windows.h>
#include <shobjidl_core.h>
#include <propkey.h>
#include <stdio.h>
int main()
{
CoInitialize(NULL);
IShellItem2* item;
if (SUCCEEDED(SHCreateItemFromParsingName(L"c:\\path\\photo.jpg", NULL, IID_PPV_ARGS(&item))))
{
LPWSTR str;
if (SUCCEEDED(item->GetString(PKEY_Photo_CameraModel, &str)))
{
wprintf(L"Model: %s\n", str);
CoTaskMemFree(str);
}
item->Release();
}
CoUninitialize();
return 0;
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论