Windows Develop Bookmark and Share   
 index > Windows Forms General > PictureBox Transparency Color
 

PictureBox Transparency Color

Ok, I know this must be simple, but I can't see to find it any where. I have a picturebox on a usercontrol. I want the background color of the image (in this case its white) to be the same color as the usercontrol. The toolstripbutton provides the ImageTransparentColor to do this, but I can't for the life of me find how to accomplish the same thing with the PictureBox. Any Ideas?

Thanks

HomeBoy  Saturday, December 15, 2007 7:13 AM

During design time you can create a user control internally using a picturebox, change the inDesigntime properties to modify the pixels of the image.
Juan Carlos Ruiz [BogotaDotNet.org]  Wednesday, December 19, 2007 1:59 PM

See the following code to make the image transperent......

please mark the post as answer if you find it helpful.

Code Block

private void Form1_Load(object sender, EventArgs e)

{

Bitmap pictureBoxImage = new Bitmap("C:\\ImagePath.jpg");

pictureBox1.Image = MakeTransperent(pictureBoxImage, Color.White);

}

private Bitmap MakeTransperent(Bitmap bmp, Color color)

{

Bitmap tmpBmp = new Bitmap(bmp.Width, bmp.Height,System.Drawing.Imaging.PixelFormat.Format32bppArgb);

tmpBmp.SetResolution(bmp.HorizontalResolution, bmp.VerticalResolution);

Graphics g = Graphics.FromImage(tmpBmp);

g.DrawImage(bmp, 0, 0);

g.Dispose();

bmp.Dispose();

for (int x = 0; x < tmpBmp.Width; x++)

{

for (int y = 0; y < tmpBmp.Height; y++)

{

if (tmpBmp.GetPixel(x, y).ToArgb() == color.ToArgb())

tmpBmp.SetPixel(x, y, Color.FromArgb(0, color));

}

}

return tmpBmp;

}

Chintankumar  Monday, December 17, 2007 12:00 PM

So I take it that there is no design time support. I guess I could apply this to the image that was loaded at design time durring the load event, but I was looking for some design time support.

Thank you

HomeBoy Out

HomeBoy  Tuesday, December 18, 2007 3:13 AM

Hi you can create you own Control by inherating PictureBox and addown Image property ...

so now Image property will have logic to apply the image after applying effect and then call the base Property.

and use this control in you aplication

Chintankumar  Wednesday, December 19, 2007 1:34 PM

if you need to set a transparent color and no to use transparency values (as a see reading your post) this could be help you:

Code Block

((Bitmap)(pictureBox1.Image)).MakeTransparent(Color.Magenta);

This code set a image color to transparent, so this color doesn't appear and you see the picturebox background.
Juan Carlos Ruiz [BogotaDotNet.org]  Wednesday, December 19, 2007 1:56 PM

During design time you can create a user control internally using a picturebox, change the inDesigntime properties to modify the pixels of the image.
Juan Carlos Ruiz [BogotaDotNet.org]  Wednesday, December 19, 2007 1:59 PM

You can use google to search for other answers

Custom Search

More Threads

• Stored Procedure Wisdom
• Have my program select menu items for me
• ListVIew and OnSelected Index Changed Event in vb.NET
• sizing the windows forms to fill the screen resolution independent
• Programmatically scrolling the TextBox / RichTextBox
• Force application exit from ApplicationContext constructor
• DataGridView: One double click calls both CellMouseClick and CellMouseDoubleClick
• MS Word in VB.NET 2005
• CRM has a bug
• Setup Form to be Only Loaded Once