views:

351

answers:

1

I'd like to overlay a number of images (PNG, same size for all, with transparency). So far, my code is as follows.

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

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

Now, I would like to overlay one more image, but this is based on a user's input from a textbox. So, to get that image, we need to take the user's input, and get the respective resource file.

I do it as follows:

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

And this correctly finds the image stream.

Now, I try and overlay the images:

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

However, this overlay doesn't seem to work.

Note that if I do something like this:

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

The overlay works correctly.

So question is: Why is the overlay not working from the stream?

Edit: It turns out that the overlay does actually work, but seems to overlay an enlarged image rather than the true size. Would there be any reason for this?

A: 

I have the same problem - I've tracked the problem to DPI of image being overlaid and DPI of image that is overlay. Check those two values, and try changing them before doing DrawImage

Vnuk