【发布时间】:2014-03-12 03:14:47
【问题描述】:
大家好,我正在尝试找到一种方法来循环浏览我的资源并仅查找标题中包含“GAME”的资源。
我可以使用这段代码很好地做到这一点:
Dim ResourceSet As Resources.ResourceSet = My.Resources.ResourceManager.GetResourceSet(Globalization.CultureInfo.CurrentCulture, True, True)
For Each Dict As DictionaryEntry In ResourceSet.OfType(Of Object)()
If TypeOf (Dict.Value) Is Drawing.Image Then
If InStr(Dict.Key, "GAME") <> 0 Then
Dim newPictureBox As New Button
Dim s As Stream = Me.GetType().Assembly.GetManifestResourceStream(Dict.Key)
Dim bmp As New Bitmap(s)
newPictureBox.BackgroundImage = Image.FromStream(Dict.Value)
newPictureBox.Tag = Dict.Value
newPictureBox.Name = "img_" & Dict.Value
newPictureBox.Width = bmp.Width.ToString()
newPictureBox.Height = bmp.Height.ToString()
FlowLayoutPanelNES.Controls.Add(newPictureBox)
AddHandler newPictureBox.Click, AddressOf newPictureBox_Click
bmp.Dispose()
End If
End If
Next
但是,一旦我尝试将该资源图像放入位图中,就会出现错误:
Value of 'null' is not valid for 'stream'.
上线:
Dim bmp As New Bitmap(s)
为了将它加载到位图以及按钮的 BackgroundImage 中,我会缺少什么?
【问题讨论】:
标签: vb.net bitmap resources embedded-resource