Overlaying images from stream in VB.NET

谁都会走 提交于 2019-12-12 01:32:48

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/1966866/overlaying-images-from-stream-in-vb-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!