从图片文件中获取相机型号在C++中。

huangapple go评论70阅读模式
英文:

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.从图片文件中获取相机型号在C++中。

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 &lt;windows.h&gt;
#include &lt;shobjidl_core.h&gt;
#include &lt;propkey.h&gt;
#include &lt;stdio.h&gt;

int main()
{
    CoInitialize(NULL);
    IShellItem2* item;
    if (SUCCEEDED(SHCreateItemFromParsingName(L&quot;c:\\path\\photo.jpg&quot;, NULL, IID_PPV_ARGS(&amp;item))))
    {
        LPWSTR str;
        if (SUCCEEDED(item-&gt;GetString(PKEY_Photo_CameraModel, &amp;str)))
        {
            wprintf(L&quot;Model: %s\n&quot;, str);
            CoTaskMemFree(str);
        }
        item-&gt;Release();
    }
    CoUninitialize();
    return 0;
}

huangapple
  • 本文由 发表于 2023年2月24日 16:52:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/75554418.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定