I've been experimenting with Windows 8 and Metro UI, I've written a perfectly reasonable load of a bitmap image, but it doesn't seem to be loading, any help is appreciated.
Public Sub New(Image As String)
Debug.Print("ms-resource://MyAssembly/" & Image)
Img = New ImageBrush()
Dim Bitmap As New BitmapImage()
Bitmap.UriSource = New Uri("ms-resource://MyAssembly/" & Image, UriKind.Absolute)
Img.ImageSource = Bitmap
Width = Bitmap.PixelWidth
Height = Bitmap.PixelHeight
Debug.Print("Height: " & Height & " Width: " & Width)
End Sub
In this example Width and Height always take values of zero. It is rendered in the same class..
Public Sub Render(X As Integer, Y As Integer, Canv As Canvas)
Dim Sprite As New Shapes.Rectangle
Sprite.Width = CDbl(Width)
Sprite.Height = CDbl(Height)
Sprite.Fill = Img
Sprite.SetValue(Canvas.TopProperty, CDbl(Y))
Sprite.SetValue(Canvas.LeftProperty, CDbl(X))
Canv.Children.Add(Sprite)
End Sub
End Class
And here is where it is created/called:
V = New Sprite("Images/Test.bmp")
gameRoot.Children.Clear()
V.Render(100, 100, gameRoot)
===
it isn't a problem with my canvas object, because if i fill it with Sprite.Fill = New SolidColorBrush(Colors.White)
then it works fine, and I see a white square on my screen, the bitmap in question is set to "Copy Always", and is in the destination folder when i view it.
I'm not quite sure what I'm doing wrong.
Well I managed to figure this out myself.
You can get a base uri by using Me.Uri; or in C# This.Uri.
Here is the finished code that will enable anyone to load a bitmap image into a canvas; and even rotate it.
I wrote this myself, so anyone who discovers it having the same problem can feel free to use it as they please.
Image must take the format "FilePath/Image.extension"