Adding Image at runtime causes exception

A

Adam Maltby

Hi,

I am adding an new picbox and animated gif to it at runtime
Dim img As Image = Image.FromFile(Application.StartupPath & "\animation.gif")
With pic_Wait
.Location = New Point(300, 250)
.Width = 72
.Height = 101
.BackColor = Color.Transparent
.BorderStyle = BorderStyle.None
.Image = img
End With

When I run this code it exceptions out with a general GDI+ error.

Help please! :)

Cheers
Adam
 
K

Ken Tucker [MVP]

Hi,

It might be because of the backcolor of the picture box being
transparent. Try it with out it.


Ken
----------------
Hi,

I am adding an new picbox and animated gif to it at runtime
Dim img As Image = Image.FromFile(Application.StartupPath &
"\animation.gif")
With pic_Wait
.Location = New Point(300, 250)
.Width = 72
.Height = 101
.BackColor = Color.Transparent
.BorderStyle = BorderStyle.None
.Image = img
End With

When I run this code it exceptions out with a general GDI+ error.

Help please! :)

Cheers
Adam
 
A

Adam Maltby

Hi,

It fails even if I take out backcolor.
It always fails where the image is specified be it whether i do it by putting the image file in a dim and passing that to .image or if i remove the dim and specify directly at .image

Cheers
Adam
 
J

james

I had a similar problem with a splash screen that didn't want to get the
image correctly and used this to correct it:
Private Sub Splash_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles MyBase.Load

Me.BackgroundImage = Image.FromFile(mypath() + "\Flowers\Splash.jpg")

Me.Height = Me.BackgroundImage.Height

Me.Width = Me.BackgroundImage.Width

End Sub

Private Function mypath() As String

Return _

Path.GetDirectoryName([Assembly].GetExecutingAssembly().Location)

End Function

I tried to use Application.StartupPath and it would give problems on
different machines. This function
eliminated the problem.
Hope it at least gives you another thing to try.
james




Hi,

I am adding an new picbox and animated gif to it at runtime
Dim img As Image = Image.FromFile(Application.StartupPath &
"\animation.gif")
With pic_Wait
.Location = New Point(300, 250)
.Width = 72
.Height = 101
.BackColor = Color.Transparent
.BorderStyle = BorderStyle.None
.Image = img
End With

When I run this code it exceptions out with a general GDI+ error.

Help please! :)

Cheers
Adam



--------------------------------------------------------------------------------


Hi,

I am adding an new picbox and animated gif to it at runtime
Dim img As Image = Image.FromFile(Application.StartupPath &
"\animation.gif")
With pic_Wait
.Location = New Point(300, 250)
.Width = 72
.Height = 101
.BackColor = Color.Transparent
.BorderStyle = BorderStyle.None
.Image = img
End With

When I run this code it exceptions out with a general GDI+ error.

Help please! :)

Cheers
Adam
 
J

james

I know that was not all of your code for loading the image. But, I did not
see where you assigned "img" to your picturebox so that it could actually
display it. That itself would cause a general error in GDI+.
Maybe, you should post more of the code you are using.
james

I'm afraid that did not work either.......
 
A

Adam Maltby

It was on the first pose in the line above the With entry.

But for reference it was:

Dim img As Image = Image.FromFile(Application.StartupPath & "\animation.gif")


Cheers
Adam
 

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