我目前正在尝试将多张图片分层到一个复合图片中,这些图片是根据玩家肖像的几个正面图片构建的。
通常用于从资源中抓取图像并将它们放入图片框/等等,我只需要#34; .Image = My.Resources.ResourceManager.GetObject(filename)"。
但是我需要转移到一个不接受对象的位图。我从几个谷歌搜索结果中找到了以下代码,但该文件被排除在外" null的值对于' stream' ",pHead是"没什么"。因此,我假设代码无法找到该文件。
中断导致下面代码的最后一行。
任何帮助或更简单的替代方案都会受到欢迎。
Dim GenderText As String = ""
Select Case ListCharacter(ActiveChar).Gender
Case eGender.Male : GenderText = "masc"
Case eGender.Female : GenderText = "fem"
End Select
Dim Prefix As String = ""
Dim Suffix As String = ".png"
Dim myAsm As System.Reflection.Assembly = System.Reflection.Assembly.GetExecutingAssembly()
' Load Head Image
' e.g. prt_fem_head_1_white.png
Dim headImageName As String = "prt_" & GenderText & "_head_" & CharApp.HeadStyle & "_" & CharApp.SkinColour
Dim pHead As Bitmap = New Bitmap(myAsm.GetManifestResourceStream(Me.GetType, headImageName & Suffix))
PS。还有/没有后缀的bug。
编辑#1;
据我所知,我已经找到了资源根目录所需的前缀。但是,这仍然不适用于任何变化。
编辑#2;
我已经通过其属性仔细检查了资源位置。
" C:\ Users \ CLEO \ Documents \ Visual Studio 2015 \ Projects \ Storytime \ Storytime \ Resources \ prt_fem_head_1_white.png"
答案 0 :(得分:-1)
解决。我将代码更改为我在Resources Designer代码中找到的更简单的代码。以下是非常原始的,需要整理,但这就是我能够将几个图像构建到一个图片框中的方式。
' Load Face
Dim PortraitLocation As New Point(573, 51)
Dim CharApp As New Character.cAppearance : CharApp = ListCharacter(ActiveChar).Appearance
' Dim pHead, pEyes, pNose, pMouth, pBase, pHair As New PictureBox
Dim FaceCanvas As New PictureBox
Dim GenderText As String = ""
Select Case ListCharacter(ActiveChar).Gender
Case eGender.Male : GenderText = "masc"
Case eGender.Female : GenderText = "fem"
End Select
Dim resourceCulture As Global.System.Globalization.CultureInfo
Dim headImageName As String = "prt_" & GenderText & "_head_" & CharApp.HeadStyle & "_" & CharApp.SkinColour
Dim obj As Object = My.Resources.ResourceManager.GetObject(headImageName, resourceCulture)
Dim phead As Bitmap = CType(obj, System.Drawing.Bitmap)
Dim eyesImageName As String = "prt_" & GenderText & "_eyes_" & CharApp.EyeStyle & "_" & CharApp.SkinColour
Dim obj2 As Object = My.Resources.ResourceManager.GetObject(eyesImageName, resourceCulture)
Dim pEyes As Bitmap = CType(obj2, System.Drawing.Bitmap)
Dim noseImageName As String = "prt_" & GenderText & "_nose_" & CharApp.NoseStyle & "_" & CharApp.SkinColour
Dim obj3 As Object = My.Resources.ResourceManager.GetObject(noseImageName, resourceCulture)
Dim pNose As Bitmap = CType(obj3, System.Drawing.Bitmap)
Dim mouthImageName As String = "prt_" & GenderText & "_mouth_" & CharApp.MouthStyle & "_" & CharApp.SkinColour
Dim obj4 As Object = My.Resources.ResourceManager.GetObject(mouthImageName, resourceCulture)
Dim pMouth As Bitmap = CType(obj4, System.Drawing.Bitmap)
Dim hairImageName As String = "prt_" & GenderText & "_hair_" & CharApp.HairStyle & "_" & CharApp.HairColour
Dim obj5 As Object = My.Resources.ResourceManager.GetObject(hairImageName, resourceCulture)
Dim pHair As Bitmap = CType(obj5, System.Drawing.Bitmap)
Dim bodyImageName As String = "prt_" & GenderText & "_body_" & CharApp.SkinColour
Dim obj6 As Object = My.Resources.ResourceManager.GetObject(bodyImageName, resourceCulture)
Dim pBody As Bitmap = CType(obj6, System.Drawing.Bitmap)
Dim g As Graphics = Graphics.FromImage(pBody)
g.DrawImage(phead, 0, 0)
g.DrawImage(pEyes, 0, 0)
g.DrawImage(pNose, 0, 0)
g.DrawImage(pMouth, 0, 0)
g.DrawImage(pHair, 0, 0)
With FaceCanvas
.Location = PortraitLocation
.Size = New Size(50, 50)
.Image = pBody
.BackColor = Color.Transparent
End With
Me.Controls.Add(FaceCanvas)