C# School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a C# Expert!

Join 300,480 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,773 people online right now. Registration is fast and FREE... Join Now!




GDI+ Aplha Blend Transparency

 

GDI+ Aplha Blend Transparency, C#

Mr.Penetration

3 Jul, 2009 - 05:42 AM
Post #1

New D.I.C Head
*

Joined: 3 Jul, 2009
Posts: 2

Hi! I am using GDI+ (System.Drawing;)


How to?

a color t ex: Color.Magneta ( 255.0.255 ). Will be a color i use in my images backgrounds as transparency. And it has alpha if t ex: The images has shadows etc.

So i want to make the picture transparent with that color and if the color aplha is not 255 it will blend the image witch it is painted on darker.


To alpha blend using matrix.

CODE

                        
          

            Graphics g = this.CreateGraphics();
            g.Clear(this.BackColor);
            
            Bitmap bitmap = new Bitmap(Application.StartupPath + @"\image.bmp");
            float[][] ptsArray ={
    new float[] {1, 0, 0, 0, 0},
    new float[] {0, 1, 0, 0, 0},
    new float[] {0, 0, 1, 0, 0},
    new float[] {0, 0, 0, 0.9f, 0},
    new float[] {0, 0, 0, 0, 1}};


            ColorMatrix clrMatrix = new ColorMatrix(ptsArray);
            ImageAttributes imgAttributes = new ImageAttributes();
            imgAttributes.SetColorMatrix(clrMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
            
            g.DrawImage(bitmap, new Rectangle(0, 0, bitmap.Width, bitmap.Hedight), 0, 0, bitmap.Width, bitmap.Height, GraphicsUnit.Pixel, imgAttributes);




bitmap method.

CODE


bitmap.MakeTransparent(color)






Is it possible to implement them ?... Im i soppose to use getpixel, check alpha and blend each pixel tongue.gif ?


*EDIT* - Hope this is enought moderator PsychoCoder. I have really worked on this whole day.

This post has been edited by Mr.Penetration: 3 Jul, 2009 - 07:22 AM

User is offlineProfile CardPM
+Quote Post


PsychoCoder

RE: GDI+ Aplha Blend Transparency

3 Jul, 2009 - 06:41 AM
Post #2

Dyslexics Untie!
Group Icon

Joined: 26 Jul, 2007
Posts: 14,714



Thanked: 501 times
Dream Kudos: 11450
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net, jQuery

My Contributions
Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

Post your code like this: code.gif

Thanks.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 03:47AM

Live C# Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month