0

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?

4

1 回答 1

0

我有同样的问题 - 我已经将问题跟踪到被覆盖的图像的 DPI 和被覆盖的图像的 DPI。检查这两个值,并在执行 DrawImage 之前尝试更改它们

于 2010-01-06T09:42:32.200 回答