views:

66

answers:

1

Our application draws drop shadows beneath thumbnails. It does this by creating a bitmap, getting a Graphics object using Graphics.FromImage, and then overlaying images using Graphics.DrawImage. I'm using it today for the first time over remote desktop, and it looks awful, because the shadows are being dithered. I don't know whether this is happening during the overlaying, or in the RDP client. Is there a way for me to determine whether the final image will be dithered, either by looking at the image, the graphics object, or the screen settings, so I can omit the shadow?

+1  A: 

you can use the System.Windows.Forms.SystemInformation.TerminalServerSession variable to detect if you are in RDP mode and degrade accordingly.

I do not know a way to detect whether the RDP client does dithering or whether the deskto's colour depth is shifted to match it but you can detect the latter via the GetDeviceCaps function:

using System.Runtime.InteropServices;

public class DeviceCaps
{
    private const int PLANES = 14;
    private const int BITSPIXEL = 12;
    [DllImport("gdi32", CharSet = CharSet.Ansi, 
        SetLastError = true, ExactSpelling = true)]
    private static extern int GetDeviceCaps(int hdc, int nIndex);
    [DllImport("user32", CharSet = CharSet.Ansi, 
        SetLastError = true, ExactSpelling = true)]
    private static extern int GetDC(int hWnd);
    [DllImport("user32", CharSet = CharSet.Ansi, 
        SetLastError = true, ExactSpelling = true)]
    private static extern int ReleaseDC(int hWnd, int hdc);
    
    public short ColorDepth()
    {
        int dc = 0;
        try 
        {
            dc = GetDC(0);
            var nPlanes = GetDeviceCaps(dc, PLANES);
            var bitsPerPixel = GetDeviceCaps(dc, BITSPIXEL);
            return nPlanes * bitsPerPixel;                 
        }
        finally
        {
            if (dc != 0)
                ReleaseDC(0, dc);
        }
    }
}

Rendering based on the colour depth is preferable to speculatively degrading by assuming the user is doing it because of RDP but may be sufficient for you.

ShuggyCoUk