I have added a cool little code snip that demonstrates a way of loading a image that was added to a project and declared "Embeded Resource" at design time, and returns a newly created D3D texture.
The code is written in vb.net and DX9.

Private Function LoadResourceImage(ByVal ResourceImageName As String) As Direct3D.Texture
        Dim Mem As New IO.MemoryStream()
        Dim Img As Bitmap

        ' attempt to create bitmap from embeded resource
        Img = New Bitmap(Me.GetType, ResourceImageName)

        ' save image to memory stream
        Img.Save(Mem, Drawing.Imaging.ImageFormat.Png)

        ' seek to start of stream
        Mem.Seek(0, IO.SeekOrigin.Begin)

        ' attempt to load/create image we saved to memory stream
        Dim Tex As Direct3D.Texture
        Tex = Direct3D.TextureLoader.FromStream(mobjGraphics.Device, Mem)

        ' done with varibles
        Mem.Close()
        Mem = Nothing
        Img.Dispose()
        Img = Nothing

        ' return reference to texture
        Return Tex
End Function

Add comment



biuquote
  • Comment
  • Preview
Loading






Created by: X

Just another personal website in this crazy online world

Name of author Dean Lunz (aka Created by: X)
Computer programming nerd, and tech geek.
About Me -- Resume