Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim cvs As Canvas
Dim btn As Button
Dim pnl As Panel
Dim bmpInvoice As Bitmap
Dim bmpMutableBitmap As Bitmap
Dim bmpDrawableBitmap As BitmapDrawable
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")
btn.Initialize("btn")
Activity.AddView(btn,0,0,300dip,100dip)
pnl.Initialize("pnl")
Activity.AddView(pnl,0,150dip,200%x,400%y)
pnl.Color=Colors.LightGray
btn.Text="Click"
bmpInvoice=LoadBitmap(File.DirAssets,"invoice.jpg")
End Sub
Sub btn_Click
Dim destRect As Rect
'Scale is a fudge factor so that the picture is the same size on note 8 and note 4
Dim scale As Float = 100dip/133
'Make the panel the right size, if the pixel density is high then we need a bigger panel
pnl.Width=bmpInvoice.Width*scale
pnl.Height=bmpInvoice.Height*scale
destRect.Initialize(0,0,pnl.Width,pnl.Height)
'Make a mutable bitmap the same size as the panel
bmpMutableBitmap.InitializeMutable( pnl.Width,pnl.Height)
bmpDrawableBitmap.Initialize( bmpMutableBitmap)
bmpDrawableBitmap.Gravity=Gravity.FILL
'Create a canvas that draws on the mutable bitmap
cvs.Initialize2(bmpMutableBitmap)
'Now paint our invoice on the canvas on the mutable bitmap
cvs.DrawBitmap(bmpInvoice,Null,destRect)
pnl.SetBackgroundImage(bmpDrawableBitmap.Bitmap)
End Sub