transparent color is black

graphics.clear(color.transparent) is not transparent

Page 1 of 1

9 Replies - 23871 Views - Last Post: 29 March 2010 - 08:16 AM Rate Topic: -----

#1 new Member()  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 19-February 09

transparent color is black

Posted 19 February 2009 - 08:07 PM

Hi guys,

I have searched all over the place, but couldn't find the answer to my problem.

I have a picturebox that I am putting multiple resource images into. They are rectangles, but are smaller than the box.
I want the blank area to show the form's background image.

I first clear the graphics object with the transparent color, then add the images.
But the area around the images is black, not transparent.

How do I stop the black from showing?
Would the form's transparency key have anything to do with it?

Here's a sample my current code:

private void DrawImages()
{
	Point pnt1 = new Ponit(10, 10);
	Point pnt2 = new Point(10, 50);

	Graphics myGraphics = pictureBox1.CreateGraphics();
	myGraphics.Clear(Color.Transparent);

	myGraphics.DrawImage(Properties.Resources.img1, pnt1);
	myGraphics.DrawImage(Propertise.Resources.img2, pnt2);
}



Thanks for your help,

James

Is This A Good Question/Topic? 0
  • +

Replies To: transparent color is black

#2 Core  Icon User is offline

  • using System.Linq;
  • member icon

Reputation: 774
  • View blog
  • Posts: 5,097
  • Joined: 08-December 08

Re: transparent color is black

Posted 19 February 2009 - 08:09 PM

Does your actual image support transparency (is it GIF or PNG)?
Was This Post Helpful? 0
  • +
  • -

#3 new Member()  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 19-February 09

Re: transparent color is black

Posted 19 February 2009 - 11:53 PM

Hi Core,

I have tried bmp, gif, png, and jpg.

Its not the actual image that I want to be transparent. Its the blank area of the picturebox around the rectangle images.
See attachment for example.

Attached Image
Was This Post Helpful? 0
  • +
  • -

#4 pr4y  Icon User is offline

  • Location: 127.0.0.1
  • member icon

Reputation: 35
  • View blog
  • Posts: 621
  • Joined: 19-September 08

Re: transparent color is black

Posted 20 February 2009 - 12:39 AM

In your picture box's properties, click on the "Background Color". When the selection menu appears, click the "Web" tab, scroll all the way to the top, and select "Transparent".

Any whitespace from the picturebox will become transparent, so long as the form's background properties are an image aswell.
Was This Post Helpful? 0
  • +
  • -

#5 new Member()  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 19-February 09

Re: transparent color is black

Posted 20 February 2009 - 12:59 AM

Hi pr4y,

I had already set the picturebox's back color to transparent.
I checked it again though, but it still doesn't work.

When there is no image in the picturebox, or I set the image in design time, I can see through it.

Thanks for your suggestion anyway.

James
Was This Post Helpful? 0
  • +
  • -

#6 pr4y  Icon User is offline

  • Location: 127.0.0.1
  • member icon

Reputation: 35
  • View blog
  • Posts: 621
  • Joined: 19-September 08

Re: transparent color is black

Posted 20 February 2009 - 01:02 AM

What is the point of your picture box having blank space around the picture? Why don't you just crop the picture box to be the same size as the image... would make a LOT more sense.

Hope this helped!
Was This Post Helpful? 0
  • +
  • -

#7 new Member()  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 19-February 09

Re: transparent color is black

Posted 20 February 2009 - 01:12 AM

I had thought of that.
The number of images in the picturebox changes, so I thought transparency would be best.
It looks like I'll have to re-size and re-position the box each time the images change.

Thanks for you help anyway.

James
Was This Post Helpful? 0
  • +
  • -

#8 pr4y  Icon User is offline

  • Location: 127.0.0.1
  • member icon

Reputation: 35
  • View blog
  • Posts: 621
  • Joined: 19-September 08

Re: transparent color is black

Posted 20 February 2009 - 01:16 AM

If you use a control array to handle your images then it would take 5 seconds to modify your code to resize / reposition the images as they are changed. If you need help with this, just be sure to ask!

Glad I could be of some assistance!
Was This Post Helpful? 0
  • +
  • -

#9 alankdkd  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 04-September 09

Re: transparent color is black

Posted 04 September 2009 - 11:08 AM

View Postnew Member(), on 19 Feb, 2009 - 07:07 PM, said:

Hi guys,

I have searched all over the place, but couldn't find the answer to my problem.

I have a picturebox that I am putting multiple resource images into. They are rectangles, but are smaller than the box.
I want the blank area to show the form's background image.

I first clear the graphics object with the transparent color, then add the images.
But the area around the images is black, not transparent.

How do I stop the black from showing?
Would the form's transparency key have anything to do with it?

Here's a sample my current code:

private void DrawImages()
{
	Point pnt1 = new Ponit(10, 10);
	Point pnt2 = new Point(10, 50);

	Graphics myGraphics = pictureBox1.CreateGraphics();
	myGraphics.Clear(Color.Transparent);

	myGraphics.DrawImage(Properties.Resources.img1, pnt1);
	myGraphics.DrawImage(Propertise.Resources.img2, pnt2);
}



Thanks for your help,

James



I think I've solved your problem, although it's probably too late to help you. Clear to another non-transparent color that's not used for something else, e.g. Color.DistinctColor. Then after your drawing is done, call Bitmap.MakeTransparent (Color.DistinctColor).

This will treat DistinctColor as transparent.
Was This Post Helpful? 0
  • +
  • -

#10 mulhearn22  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 29-March 10

Re: transparent color is black

Posted 29 March 2010 - 08:16 AM

View Postalankdkd, on 04 September 2009 - 10:08 AM, said:

View Postnew Member(), on 19 Feb, 2009 - 07:07 PM, said:

Hi guys,

I have searched all over the place, but couldn't find the answer to my problem.

I have a picturebox that I am putting multiple resource images into. They are rectangles, but are smaller than the box.
I want the blank area to show the form's background image.

I first clear the graphics object with the transparent color, then add the images.
But the area around the images is black, not transparent.

How do I stop the black from showing?
Would the form's transparency key have anything to do with it?

Here's a sample my current code:

private void DrawImages()
{
	Point pnt1 = new Ponit(10, 10);
	Point pnt2 = new Point(10, 50);

	Graphics myGraphics = pictureBox1.CreateGraphics();
	myGraphics.Clear(Color.Transparent);

	myGraphics.DrawImage(Properties.Resources.img1, pnt1);
	myGraphics.DrawImage(Propertise.Resources.img2, pnt2);
}



Thanks for your help,

James



I think I've solved your problem, although it's probably too late to help you. Clear to another non-transparent color that's not used for something else, e.g. Color.DistinctColor. Then after your drawing is done, call Bitmap.MakeTransparent (Color.DistinctColor).

This will treat DistinctColor as transparent.


Hey,

I hope you get this because your method worked, but I'm getting a thin, 1px line on the left and top edges of my image in the color that I'm using to Clear(). Any idea how to get rid of that?

TIA,
Matt
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1