在VB.NET覆盖从流的图象 [英] Overlaying images from stream in VB.NET

查看:138
本文介绍了在VB.NET覆盖从流的图象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想覆盖多个图像(PNG,同样大小都与透明度)。到目前为止,我的code是如下:

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.

我做如下:

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?

编辑: 事实证明,叠加不实际工作,但似乎叠加放大的图像,而不是真正的大小。会不会有任何原因?

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?

推荐答案

我有同样的问题 - 我已经追踪问题,以图像的DPI被覆盖和图像的DPI是叠加。检查这两个值,并尝试做的DrawImage之前改变它们

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

这篇关于在VB.NET覆盖从流的图象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆