By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,222 Members | 1,436 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,222 IT Pros & Developers. It's quick & easy.

transparency and .gif files

P: n/a
Hi,
I create a form, then place a picturebox on it.
Then I set the picturebox image to a .gif that I have
edited in GIFConstructionSet to create a transparent
background for. But when I run the code, what should be
transparent is not really transparent. Is there a property in
the picture box I need to tweak? I though the whole idea
was to put the transparency information right in the gif file.
Suggestions, clues, pointers?
Any of the above appreciated.
Thanks,
Al
Nov 23 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
I think you may still need to set the transparency in the picture's properties.
eg
dim b as new bitmap(c:\pic.bmp)
b.maketransparent(b.getpixel(0,0))
Nov 23 '05 #2

P: n/a
Thanks for getting back Andrew.
I've tried the get pixel approach
dim b as new bitmap(c:\pic.bmp)
b.maketransparent(b.getpixel(0,0))
and while it makes it "transparent", I wind up seeing the underlying
form. So it shows up as gray.
Al

--
Sent via .NET Newsgroups
http://www.dotnetnewsgroups.com
Nov 23 '05 #3

P: n/a
I've had a lot of problems with transparency of forms, with things such as
transparency key not working for me as I would have expected. The below does
work for me, though, to display a small irregularly shaped form over a base
form containing a picturebox:

In the Form constructor:
....
dim DisplayImage as new bitmap(c:\...)
DisplayImage.MakeTransparent(DisplayImage.GetPixel (0,0))
FormBorderStyle = Windows.Forms.FormBorderStyle.None
Toplevel = False
Parent = BaseForm.PictureBox
....

Protected Overrides Sub OnPaint(ByVal e As
System.Windows.Forms.PaintEventArgs)
Dim bm As New Bitmap(Me.Width, Me.Height)
Dim g As Graphics = Graphics.FromImage(bm)
g.Clear(DisplayImage.GetPixel(0, 0))
bm.MakeTransparent(DisplayImage.GetPixel(0, 0))
g.Dispose()
BackgroundImage = bm
TransparencyKey = DisplayImage.GetPixel(0, 0)
e.Graphics.DrawImage(DisplayImage, 0, 0, ScaleWidth, ScaleHeight)
MyBase.OnPaint(e)
End Sub
Nov 23 '05 #4

P: n/a
Thanks Andrew, Time for me to watch some football, but will try your
code tomorrow.
Will let you know how I make out.
Al
--
Sent via .NET Newsgroups
http://www.dotnetnewsgroups.com
Nov 23 '05 #5

P: n/a
Hi,

The transparent background will let the picture boxes background to
show through. I believe you want to see the form background instead. I
would draw the gif on the form in the forms paint event instead of using a
picturebox.

Ken
--------------
"Al_C" <ac****@bicnet.net> wrote in message
news:O8**************@TK2MSFTNGP09.phx.gbl...
Hi,
I create a form, then place a picturebox on it.
Then I set the picturebox image to a .gif that I have
edited in GIFConstructionSet to create a transparent
background for. But when I run the code, what should be
transparent is not really transparent. Is there a property in
the picture box I need to tweak? I though the whole idea
was to put the transparency information right in the gif file.
Suggestions, clues, pointers?
Any of the above appreciated.
Thanks,
Al

Nov 23 '05 #6

P: n/a
Hi Ken & Andrew,
My ultimate goal is to have an image moving around the screen.
So I need to be able to change its location based on the timer popping.
I was able to establish the transparencykey in the form constructor and
when then when the timer pops -

Me.PictureBox1.Location = New System.Drawing.Point(x, y)

Problem I have is that the transparency key applies to everything
including the form. And that it actually lets me see right through the
whole application all the way to the desktop ;) All I want is for it to
be transparent to the form.

First I can't make things transparent and now they are too transparent!!
;)
Al


--
Sent via .NET Newsgroups
http://www.dotnetnewsgroups.com
Nov 23 '05 #7

P: n/a
Hi,
I finally have it almost working.
On program startup I read in the image I want from disk and establish the
transparency color. This works fine as long as I have a background color
for the form. But soon as I change from a background color to a background
image I get a picture box with a control color around my image.

Dim DisplayImage As New Bitmap("c:\b1.gif") 'on startup
outside the form construct

DisplayImage.MakeTransparent(DisplayImage.GetPixel (0, 0))
Me.PictureBox1.Image = CType(DisplayImage, System.Drawing.Image)

For now I have the last two lines hard coded in the form construct.

Then I have a timer_tick event that
x = x + 1
tick = tick + tick + x
y = 200 + Sin(tick) * 100 'just to get a rather up and
down y value
Me.PictureBox1.Location = New System.Drawing.Point(x, y) 'redraw the
picture box.

This works great as long as I don;t have an image as a background on the
form.

Any thoughts?

"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:uD**************@TK2MSFTNGP12.phx.gbl...
Hi,

The transparent background will let the picture boxes background to
show through. I believe you want to see the form background instead. I
would draw the gif on the form in the forms paint event instead of using a
picturebox.

Ken
--------------
"Al_C" <ac****@bicnet.net> wrote in message
news:O8**************@TK2MSFTNGP09.phx.gbl...
Hi,
I create a form, then place a picturebox on it.
Then I set the picturebox image to a .gif that I have
edited in GIFConstructionSet to create a transparent
background for. But when I run the code, what should be
transparent is not really transparent. Is there a property in
the picture box I need to tweak? I though the whole idea
was to put the transparency information right in the gif file.
Suggestions, clues, pointers?
Any of the above appreciated.
Thanks,
Al


Nov 23 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.