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

Loading PictureBox images using OpenFileDialog

P: n/a
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?
Nov 21 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
"..:: Kevin ::.." <Ke***@discussions.microsoft.com> schrieb:
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?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #2

P: n/a
I have tried with a bmp image and a gif image and the problem is the same for
both formats

"Herfried K. Wagner [MVP]" wrote:
"..:: Kevin ::.." <Ke***@discussions.microsoft.com> schrieb:
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?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #3

P: n/a
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
"..:: Kevin ::.." <Ke***@discussions.microsoft.com> schreef in bericht
news:2D**********************************@microsof t.com...
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?

Nov 21 '05 #4

P: n/a
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
"Cor Ligthert [MVP]" wrote:
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
"..:: Kevin ::.." <Ke***@discussions.microsoft.com> schreef in bericht
news:2D**********************************@microsof t.com...
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?


Nov 21 '05 #5

P: n/a
Kevin,

Maybe is yours better and did I even write the wrong method in my previous
reply.

However I use normally is. (watch typos, I typed most it in this message)

\\\
If openFileDialog1.ShowDialog() = DialogResult.OK Then
picImage.Image = Image.FromFile(openFileDialog1.FileName)
End If
////

http://msdn.microsoft.com/library/de...mfiletopic.asp

Have a look at the overloaded method as well.

I hope this helps,

Cor
Nov 21 '05 #6

P: n/a
"..:: Kevin ::.." <Ke***@discussions.microsoft.com> schrieb:
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()
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #7

P: n/a
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 in Houston
"Herfried K. Wagner [MVP]" wrote:
"..:: Kevin ::.." <Ke***@discussions.microsoft.com> schrieb:
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()
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #8

P: n/a
"Dennis" <De****@discussions.microsoft.com> schrieb:
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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.