BitmapForCaching Question

I’m trying to make another version of the BitmapForCaching method (Page Not Found — Xojo documentation) to extend it for the Window object (as seen below) since I can no longer directly access the windows graphics object in the latest release.

It seems to work but is it ok to replace g.ScaleX and g.ScaleY with w.ScaleFactor or could this cause unforeseen problems? Would it be better to directly call w.BitmapForCaching without the mask parameter to create a 1x1 pixel image and then use that’s g.ScaleX and g.ScaleY instead?

[code]Public Function BitmapForCaching(Extends w as Window, width as integer = -1, height as integer = -1, WithMask as boolean = False) as picture

#Pragma BackgroundTasks False

Dim pic As Picture

If WithMask then
pic = New Picture(widthw.ScaleFactor, heightw.ScaleFactor, 32)
pic = New Picture(widthw.ScaleFactor, heightw.ScaleFactor)
End If

// Set the resolutions
pic.HorizontalResolution = 72 * w.ScaleFactor
pic.VerticalResolution = 72 * w.ScaleFactor
pic.Graphics.ClearRect(0, 0, pic.Width, pic.Height) = w.ScaleFactor = w.ScaleFactor

If WithMask then = w.ScaleFactor = w.ScaleFactor
End If

Return pic

End Function

I’m curious why you need this.

To create a new HiDPI picture with a mask when I only know the parent window a custom canvas class object is on and I have no direct graphics object properties to access. It’s also helpful if you want to copy a resource image into a new image so you can manipulate it and you can only do this if you can access the new image’s graphics and mask properties, since a resource image’s graphics property is always nil.

Just FYI, you can always use picture.CopyMask and Picture.CopyColorChannels.

Thanks, Greg. Handy to know.

There’s nothing wrong with what you are doing however.