Quantcast
Viewing all articles
Browse latest Browse all 18858

ICC/ICM Profile for Controls

Hello,

how can an ICC / ICM Color Profile be assigned to a Control (especially to a Canvas) in WPF?

I need to display my Canvas and all the Children (for example TextBlock and Image Control) using a selected Color Profile. Using Windows API there is a possibility in gdi32.dll to assign a Profile to a Control:

[DllImport("gdi32.dll", SetLastError = true)]
static extern int SetICMMode(IntPtr hDC, int iEnableICM);

[DllImport("gdi32.dll", SetLastError = true)]
static extern bool SetICMProfile(IntPtr hDC, string lpFileName);

How can this be assigned to a Control?

I found a Solution for Windows Forms: http://www.xtremevbtalk.com/archive/index.php/t-280621.html
The Problem in this Thread was that the Form was DoubleBuffered. When DoubleBuffered is set to false, Color Profile works. I think, that WPF is always DoubleBuffered?

Can this be ported to WPF? Also what I need to do is to switch the Color Profile at runtime without recreating all the Controls.

My Sample Source Code is following (see comments):

private void Button_Click(object sender, RoutedEventArgs e)
{
    HwndSource hwndSource = PresentationSource.FromVisual(this.mainCanvas) as HwndSource;

    if (hwndSource != null)
    {
        IntPtr handle = GetDC(hwndSource.Handle);
        int SetModeResult = SetICMMode(handle, 2); // Turn on ICM Mode -> returns 1 which means OK according to MSDN Documentation

        bool SetProfileResult = SetICMProfile(handle, @"C:\MyProfile.icc"); // Returns true but nothing changes
    }
}

Is there any other way to archive this?

Thank you for your Help!

Kind Regards
Stefan



Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>