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:
B4X:
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
B4X:
Dim Preview As Panel
in Globals. The image logo.png does exist and can be loaded and referenced otherwise.

What am I missing?
 

yttrium

Active Member
Licensed User
Longtime User
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

stevel05

Expert
Licensed User
Longtime User
You've initialized the Bitmap and Rect, have you initialized the Canvas?
 
Upvote 0

yttrium

Active Member
Licensed User
Longtime User
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
Cookies are required to use this site. You must accept them to continue using the site. Learn more…