Drawing on a canvas - nullpointerexception

yttrium

Active Member
Licensed User
Longtime User
Hey all, I get a fatal null pointer exception whenever I execute the following code:
Code: Copy
Dim MyCanvas As Canvas
Dim Bitmap1 As Bitmap
Bitmap1.Initialize(File.DirAssets, "logo.png")
Dim DestRect As Rect
DestRect.Initialize(10dip, 10dip, 10dip + 100dip, 10dip + 100dip)
MyCanvas.DrawBitmap(Bitmap1,, DestRect)
Preview.SetBackgroundImage(MyCanvas.Bitmap)

I use
Code: Copy
Dim Preview As Panel
in Globals. The image logo.png does exist and can be loaded and referenced otherwise.

What am I missing?
 
Sorry, I wrote that incorrectly. That line is Bitmap1, Null, DestRect as the documentation states should be used to return the full source bitmap.
 
Upvote 0
You've initialized the Bitmap and Rect, have you initialized the Canvas?

Oh, wow, how stupid of me. Yup, that fixed it.

Okay, as another little question, how can I make a Panel or ImageView zoom instead of stretch to fit? The only options are Fill, Center, and TopLeft.
 
Last edited:
Upvote 0
Back
Top