WcsGetDefaultColorProfile的代码示例

Ran*_*ard 5 windows winapi color-management color-profile

有没有人有一个工作代码示例显示对Windows颜色系统函数WcsGetDefaultColorProfile的调用来获取特定设备的默认颜色配置文件?当我为pDeviceName参数传递null时,它适用于我,但是当我尝试传递监视器的设备名称时,我总是返回错误代码ERROR_FILE_NOT_FOUND.

我更喜欢C#的例子,但我会接受任何我能得到的东西.我无法在任何地方找到任何新的WCS配置文件管理功能的示例代码.

Mat*_*t M 5

我遇到了同样的问题,你沮丧的原因是MSDN文档对于WcsGetDefaultColorProfile的pDeviceName参数是不正确的(或者最好是误导性的).

MSDN doc(http://msdn.microsoft.com/en-us/library/dd372247 ( v=vs.85) .aspx)表示pDeviceName是指"设备的名称",对于显示设备,人们会假设是一个Windows显示设备名称,例如"\.\ DISPLAY1",在EnumDisplayDevices的DISPLAY_DEVICE结构的DeviceName参数中返回.

实际上,这里需要的是监视器的DeviceKey参数,特别是在EnumDisplayDevices中使用EDD_GET_DEVICE_INTERFACE_NAME标志时获得的DeviceKey.

所以工作代码看起来像这样,假设szDisplayDeviceName已设置为显示您关心的设备名称,例如"\.\ DISPLAY1":

WCHAR szPath[MAX_PATH];
DISPLAY_DEVICE dd;
dd.cb = sizeof(dd);
if (EnumDisplayDevices(szDisplayDeviceName, 0, &dd, EDD_GET_DEVICE_INTERFACE_NAME))
{
    if (WcsGetDefaultColorProfile(WCS_PROFILE_MANAGEMENT_SCOPE_CURRENT_USER, 
          dd.DeviceKey,
          CPT_ICC,
          CPST_PERCEPTUAL,
          1,  // dwProfileID -- doesn't seem to matter what value you use here
          MAX_PATH * sizeof(WCHAR),
          szPath))
    {
        PROFILE profile;
        profile.cbDataSize = (DWORD)(wcslen(szPath) + 1) * sizeof(WCHAR);
        profile.dwType = PROFILE_FILENAME;
        profile.pProfileData = (PVOID)szPath;

        HPROFILE hProfile = OpenColorProfile(&profile,
           PROFILE_READ, FILE_SHARE_READ, OPEN_EXISTING);

        // now do something with the profile
    }
}
Run Code Online (Sandbox Code Playgroud)


Max*_*xim 0

添加以下结构:

public const uint ProfileRead = 1;

public enum FileShare : uint
{
    Read = 1,
    Write = 2,
    Delete = 4
};

public enum CreateDisposition : uint
{
    CreateNew = 1,
    CreateAlways = 2,
    OpenExisting = 3,
    OpenAlways = 4,
    TruncateExisting = 5
Run Code Online (Sandbox Code Playgroud)

};

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public class ProfileFilename
{
    public uint type;
    [MarshalAs(UnmanagedType.LPTStr)]
    public string profileData;
    public uint dataSize;

    public ProfileFilename(string filename)
    {
        type = ProfileFilenameType;
        profileData = filename;
        dataSize = (uint)filename.Length * 2 + 2;
    }
};

[DllImport("mscms.dll", SetLastError = true, EntryPoint = "GetStandardColorSpaceProfileW", CallingConvention = CallingConvention.Winapi)]
static extern bool GetStandardColorSpaceProfile(    uint machineName,
                                                    LogicalColorSpace profileID,
                                                    [MarshalAs(UnmanagedType.LPTStr), In, Out] StringBuilder profileName,
                                                    ref uint size);

[DllImport("mscms.dll", SetLastError = true, EntryPoint = "OpenColorProfileW", CallingConvention = CallingConvention.Winapi)]
    static extern IntPtr OpenColorProfile(  [MarshalAs(UnmanagedType.LPStruct)] ProfileFilename profile,
                                            uint desiredAccess,
                                            FileShare shareMode,
                                            CreateDisposition creationMode);
Run Code Online (Sandbox Code Playgroud)

打开默认配置文件的示例:

public openDefaultColorProfile()
{ 
    StringBuilder profileName = new StringBuilder(256);
    uint size = (uint)profileName.Capacity * 2;
    success = GetStandardColorSpaceProfile(0, LogicalColorSpace.WindowsColorSpace, profileName, ref size);

    ProfileFilename sRGBFilename = new ProfileFilename(profileName.ToString());
    IntPtr hSRGBProfile = OpenColorProfile(sRGBFilename, ProfileRead, FileShare.Read, CreateDisposition.OpenExisting);
}
Run Code Online (Sandbox Code Playgroud)