Draw picture in picture

As always drawing in HiDPI mode defeats me. I need to draw a small icon in an existing icon. But the graphics is nil.

dim thePictureLight as Picture = new picture(16, 16, 32)
thePictureLight = ListboxIcons.getPictureLight(LevelList.subhead(currentNode).text, false)

dim OffSet as Integer = thePictureLight.Width/2
dim thePath as String = LevelList.subhead(currentNode).thePath
if ImapStatus.IndexOf(thePath) > -1 then
  for currentPic as Integer = 0 to thePictureLight.ImageCount - 1
    thePictureLight.ImageAt(currentPic).Graphics.DrawPicture(exclamation, OffSet, OffSet, exclamation.Width/2, exclamation.Height/2, 0, 0, exclamation.Width, exclamation.Height)
  next 'Graphics is nil here
end if

thePictureLight is created with 2 images:

What do I need to change to get the exclamation icon into the larger icon? I think that thePictureLight isn’t mutable. But how do I get from there to a mutable picture with HiDPI?

Always check your own code first:

thePictureLight = AddExclamation(thePictureLight)

Private Function AddExclamation(original as Picture) as Picture
  
  'add exclamation icon
  
  if original = Nil then Return Nil
  
  Dim n As Integer=original.ImageCount
  If n=0 Then
    Return AddExclamationInner(original)
  Else
    Dim pp() As Picture
    n=n-1
    for i as integer=0 to n
      pp.Add AddExclamationInner(original.ImageAt(i))
    Next
    #Pragma BreakOnExceptions False
    try
      Return new Picture(original.Width, original.Height, pp)
    catch err as NilObjectException
      'ignore
    end try
    #Pragma BreakOnExceptions True
  End If
  
End Function


Private Function AddExclamationInner(OriginalPicture as Picture) as Picture
  
  'add exclamation icon
  Dim ResultPicture As New Picture(OriginalPicture.Width, OriginalPicture.Height)
  ResultPicture.Graphics.DrawPicture(OriginalPicture.CopyColorChannels, 0, 0, _
  OriginalPicture.Width, OriginalPicture.Height, _
  0, 0, _
  OriginalPicture.Width, OriginalPicture.Height)
  ResultPicture.Graphics.DrawPicture(exclamation, OriginalPicture.Width/2, OriginalPicture.Height/2, _
  exclamation.Width, exclamation.Height, _
  0, 0, _
  exclamation.Width, exclamation.Height)
  ResultPicture.ApplyMask OriginalPicture.CopyMask
  
End Function

This works almost. The smaller icon is painted correctly into the larger icon which I can see in the debugger. But returning the new picture made from pp results in a nil picture for thePictureLight. What am I doing wrong?

You have no Return ResultPicture in AddExclamationInner

1 Like

Head on desk!

1 Like

I have those moments, quite often :smiley:

You are not alone.

I even create a new Method, populate it, then I forgot to call it…

Until I was asking me why is this not working ? :wink:

1 Like
Forum for Xojo Programming Language and IDE. Copyright © 2021 Xojo, Inc.