Loading PictureBox images using OpenFileDialog

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

If I load a PictureBox image from an embedded resource within my application
it works fine but if I load the same image from a file using OpenFileDialog
(as an ImageStream or using the file name) the background color is not masked
out.

Any ideas?
 
..:: Kevin ::.. said:
If I load a PictureBox image from an embedded resource within my
application
it works fine but if I load the same image from a file using
OpenFileDialog
(as an ImageStream or using the file name) the background color is not
masked
out.

Which image format does the image have?
 
I have tried with a bmp image and a gif image and the problem is the same for
both formats
 
Kevin,

There seems something very special in you code. The OpenFileDialog is only
giving a string to use in the by instance image.fromstream command.

I hope this helps,

Cor
 
Cor,

The code I am using is as follows:

Dim ImageStream As System.IO.Stream

If openFileDialog1.ShowDialog() = DialogResult.OK Then

ImageStream = openFileDialog1.OpenFile()

If Not (ImageStream Is Nothing) Then

picImage.Image = Image.FromStream(ImageStream)

End If

End If
 
..:: Kevin ::.. said:
I have tried with a bmp image and a gif image and the problem is the same
for
both formats

BMP doesn't support transparent backcolors at all. Use the code below to
load a transparent GIF file:

\\\
Dim o As New OpenFileDialog()
If o.ShowDialog() = DialogResult.OK Then
Me.PictureBox1.Image = Image.FromFile(o.FileName)
End If
o.Dispose()
///
 
We can set colors in bitmaps to transparent in VB.Net so shouldn't bmp handle
transparent backgrounds if using 32bit bitmaps? I know you are correct
because I've tried saving 32 bit bitmaps with a color transparent and it
doesn't work.
 
Dennis said:
We can set colors in bitmaps to transparent in VB.Net so shouldn't bmp
handle
transparent backgrounds if using 32bit bitmaps? I know you are correct
because I've tried saving 32 bit bitmaps with a color transparent and it
doesn't work.

You can actually make the bitmap transparent in memory by calling its
'MakeTransparent' method, for example.
 

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

Back
Top