Click to See Complete Forum and Search --> : Image overlay from stream not working


aommaster
December 27th, 2009, 02:48 PM
Hi everyone

I have a few PNG files, with transparency and are of the same dimension that I would like to overlay.

So far, I'm using this kind of code and it seems to be working fine:

bg = New Bitmap(My.Resources.blue)
g = Graphics.FromImage(bg)

overlay = New Bitmap(tree.Image)
g.DrawImage(overlay, 0, 0)


However, the third image to be overlapped is based on a user's input into a text box. For now, assume that an image exists for any user's input text.

I do this:

Dim stream As IO.Stream = Nothing
Dim path As String = Assembly.GetName().Name.ToString() + "." + inputbox.text + ".png"
stream = Assembly.GetManifestResourceStream(path)


If I now try to overlay the stream:

overlay = New Bitmap(stream)
g.DrawImage(overlay, 0, 0)

It doesn't work (the overlay doesn't seem to do anything)

If I do this instead:

overlay = New Bitmap(My.Resources._5)
g.DrawImage(overlay, 0, 0)

The overlay does work.

Why is this happening? I would like to use the stream method, because the image to overlay is dependant on the user input.

Edit:
Poking around, I found that if the bitmap was read from the stream, the overlay did actually work. However, the image in the overlay appeared to be larger than the true size of that image. Somehow, the stream appears to be increasing the size of the image (even though the debugger doesn't appear to show that).

I'm now even more confused as to what's going on