transparency and .gif files

A

Al_C

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
 
G

Guest

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))
 
A

Al_C

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
 
G

Guest

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
 
A

Al_C

Thanks Andrew, Time for me to watch some football, but will try your
code tomorrow.
Will let you know how I make out.
Al
 
K

Ken Tucker [MVP]

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
 
A

Al_C

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
 
A

Al_C

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top