Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Transparent Key Color Isssue

Posted on 2007-10-11
11
Medium Priority
?
372 Views
Last Modified: 2012-05-05
I have a simple windows form with an image on it; I have set the transparent key of the form to match the form color rendering it transparent when the program is run.  However sometimes when the color depth is set to 32 bit on any given computer the transparent key color shows up.

Is there any way around this?

0
Comment
Question by:schenkp
  • 5
  • 3
  • 2
  • +1
11 Comments
 
LVL 22

Expert Comment

by:p_davis
ID: 20060623
what is the color value that you are using argb? can you just convert to a win32 using the color converter?
0
 

Author Comment

by:schenkp
ID: 20061021
Im just using blue 0,0,255.  
0
 

Author Comment

by:schenkp
ID: 20061026
How do i convert it to a win32 using the color converter?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 96

Expert Comment

by:Bob Learned
ID: 20061070
What is the color depth (pixel format) for the image?  Format32bppArgb?

Bob
0
 

Author Comment

by:schenkp
ID: 20061162
Not sure what you mean its just a .tif out of Photoshop....  
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 20061854
Most images are 24-bit Format24bppArgb, and the colors are slightly different between 24 bit and 32 bit images.

Bob
0
 

Author Comment

by:schenkp
ID: 20061875
Is there anyway to correct this with code?
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 1600 total points
ID: 20065693
Here is a method that will convert pixel format for an image:

using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;

public class ImageConverter
{

    /// <summary>
    /// Convert an image to the desired pixel format.
    /// </summary>
    /// <returns>Converted image</returns>
    /// <remarks>Create a Bitmap with the desired pixel format, and draw the image using
    /// a temporary Graphics object.
    /// </remarks>
    public static Image ConvertPixelFormat(Bitmap img, PixelFormat format)
    {
        Bitmap bmp = new Bitmap(img.Width, img.Height, format);
        using (Graphics gr = Graphics.FromImage(bmp))
        {
            gr.DrawImage(img, 0, 0);
        }
        return bmp;
    }
}

Example:
            Bitmap img = (Bitmap)Image.FromFile(@"C:\WINDOWS\Web\Wallpaper\Autumn.jpg");
            this.BackgroundImage = ImageConverter.ConvertPixelFormat(img, PixelFormat.Format32bppArgb);

Bob
0
 
LVL 11

Expert Comment

by:William
ID: 20074068
As well as what Bob has shown, to make sure you always have the "Actual" Color for your transparency:

        So using his example

  Bitmap img = (Bitmap)Image.FromFile(@"C:\WINDOWS\Web\Wallpaper\Autumn.jpg");
  this.BackgroundImage = ImageConverter.ConvertPixelFormat(img, PixelFormat.Format32bppArgb);
//Set the color using the actual color from the pixel....
  this.TransparencyKey = img.GetPixel( 0 , 0 );
0
 

Author Comment

by:schenkp
ID: 20074140
When using this method the background image is about four times large than the actual background, thus ony showing part of it.  How do i properly align it so it shows up the proper size?
0
 
LVL 11

Assisted Solution

by:William
William earned 400 total points
ID: 20078716
try setting the imagelayout prop...


            this.BackgroundImage = yourimage;
            this.BackgroundImageLayout = ImageLayout.Stretch;
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Integration Management Part 2
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question