Click here to Skip to main content
15,907,001 members
Home / Discussions / C#
   

C#

 
AnswerRe: some C# question Pin
N a v a n e e t h23-Jan-09 23:14
N a v a n e e t h23-Jan-09 23:14 
QuestionSecurity information in Web Pin
trinm198723-Jan-09 22:29
trinm198723-Jan-09 22:29 
QuestionSemi-Transparent icons in ListView Pin
Ankit Rajpoot23-Jan-09 21:28
Ankit Rajpoot23-Jan-09 21:28 
AnswerRe: Semi-Transparent icons in ListView Pin
DaveyM6924-Jan-09 2:20
professionalDaveyM6924-Jan-09 2:20 
GeneralRe: Semi-Transparent icons in ListView Pin
Ankit Rajpoot24-Jan-09 3:29
Ankit Rajpoot24-Jan-09 3:29 
GeneralRe: Semi-Transparent icons in ListView Pin
DaveyM6924-Jan-09 4:48
professionalDaveyM6924-Jan-09 4:48 
GeneralRe: Semi-Transparent icons in ListView Pin
DaveyM6924-Jan-09 4:57
professionalDaveyM6924-Jan-09 4:57 
GeneralSemi-Transparent icons in ListView (Yoooooohooooooo got it working now) Pin
Ankit Rajpoot24-Jan-09 4:51
Ankit Rajpoot24-Jan-09 4:51 
Hi Dave,

I got it working correctly after a few hours of Frown | :( Sigh | :sigh: D'Oh! | :doh: Cry | :(( Shucks | :-\ Shucks | :-\ Shucks | :-\ WTF | :WTF: WTF | :WTF: WTF | :WTF: . The information from Joe Pardue's articles on transparency and alpha blending got me on the right track. Really they are excellent articles. I'd recommend reading them to all those who want to get a grip on graphics processing concepts.

Transparency Tutorial with C# - Part 1[^]

Transparency Tutorial with C# - Part 2[^]

Transparency Tutorial with C# - Part 3[^]

All that was needed was this little modification:
public static Image SetImageOpacity(Image image, float opacity)
{
     Bitmap bitmap = new Bitmap(image.Width, image.Height); 
     using (Graphics g = Graphics.FromImage(bitmap)) 
     {
          // The followine statement was absent originally.
          g.FillRegion(new SolidBrush(SystemColors.Window), new Region(new Rectangle(0, 0, image.Width, image.Height)));
          ColorMatrix matrix = new ColorMatrix();
          matrix.Matrix33 = opacity; 
          ImageAttributes attributes = new ImageAttributes(); 
          attributes.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); 
          g.DrawImage(image, new Rectangle(0, 0, bitmap.Width, bitmap.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, attributes); 
     } 
     return bitmap; 
}


Originally the method did the following:
1. Create a new Bitmap object.
2. Create a new ColorMatrix object and set the alpha element (3,3) to the desired value.
3. Construct a new ImageAttributes object, associate the ColorMatrix with it, and then use this whole information to draw the input Image over the new Bitmap object.

The problem, as far as I understand now (after reading Joe's articles), was that the method was trying to draw the source image over an empty bitmap (black colored bitmap). Thus, after applying the transformation, the image goes dark instead of fading into the background color.

Now the line which I added, paints the destination bitmap with the background color of the Window, before painting the source image, so that when it is blended with the source image, the source image appears blended into the background color.

That's it.

And here's the difference:

Before[^]

After[^]
GeneralRe: Semi-Transparent icons in ListView (Yoooooohooooooo got it working now) Pin
DaveyM6924-Jan-09 5:01
professionalDaveyM6924-Jan-09 5:01 
GeneralRe: Semi-Transparent icons in ListView (Yoooooohooooooo got it working now) Pin
DaveyM6924-Jan-09 5:14
professionalDaveyM6924-Jan-09 5:14 
GeneralRe: Semi-Transparent icons in ListView (Yoooooohooooooo got it working now) Pin
Ankit Rajpoot24-Jan-09 5:55
Ankit Rajpoot24-Jan-09 5:55 
QuestionLinkintwo forms in project in win app Pin
MontSon23-Jan-09 21:09
MontSon23-Jan-09 21:09 
AnswerRe: Linkintwo forms in project in win app Pin
DaveyM6923-Jan-09 23:43
professionalDaveyM6923-Jan-09 23:43 
GeneralRe: Linkintwo forms in project in win app Pin
Wendelius24-Jan-09 0:21
mentorWendelius24-Jan-09 0:21 
GeneralRe: Linkintwo forms in project in win app Pin
nelsonpaixao24-Jan-09 5:50
nelsonpaixao24-Jan-09 5:50 
GeneralRe: Linkintwo forms in project in win app Pin
DaveyM6924-Jan-09 6:00
professionalDaveyM6924-Jan-09 6:00 
QuestionThread was being aborted. Pin
waitsunny23-Jan-09 20:53
waitsunny23-Jan-09 20:53 
AnswerRe: Thread was being aborted. Pin
EliottA23-Jan-09 20:57
EliottA23-Jan-09 20:57 
GeneralRe: Thread was being aborted. Pin
anishkannan23-Jan-09 21:08
anishkannan23-Jan-09 21:08 
GeneralRe: Thread was being aborted. Pin
#realJSOP23-Jan-09 22:17
professional#realJSOP23-Jan-09 22:17 
QuestionCreate table layout on panel Pin
anishkannan23-Jan-09 20:53
anishkannan23-Jan-09 20:53 
QuestionForm that is already visible cannot be displayed as a modal Pin
waitsunny23-Jan-09 20:53
waitsunny23-Jan-09 20:53 
AnswerRe: Form that is already visible cannot be displayed as a modal Pin
Wendelius23-Jan-09 21:21
mentorWendelius23-Jan-09 21:21 
Answerplease send me replay Pin
waitsunny23-Jan-09 20:52
waitsunny23-Jan-09 20:52 
GeneralRe: please send me replay Pin
Colin Angus Mackay24-Jan-09 1:30
Colin Angus Mackay24-Jan-09 1:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.