DesktopCanvas.ScaleFactorChanged

From Xojo Documentation

You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!
Event


DesktopCanvas.ScaleFactorChanged()

New in 2021r3

Supported for all project types and targets.

The backing store scale factor has changed and the canvas should refresh any cached bitmaps or other relevant state.

Sample Code

If you have an Image Set with multiple images for HiDPI and want to split out each of the pictures it contains, you can do so like this:

Var g As Graphics
Var p, pics() As Picture

// Break the Image into its component pictures
// Also copy the horizontal/vertical resolution and scale factors
// so that the pictures draw properly when used later.
For i As Integer = 0 To MyImageSet.ImageCount - 1
p = New Picture(MyImageSet.IndexedImage(i).Width, MyImageSet.IndexedImage(i).Height)
p.HorizontalResolution = MyImageSet.IndexedImage(i).HorizontalResolution
p.VerticalResolution = MyImageSet.IndexedImage(i).VerticalResolution
pics.Add(p)
g = p.Graphics
g.ScaleX = p.HorizontalResolution / 72
g.ScaleY = p.VerticalResolution / 72
g.DrawPicture(MyImageSet.IndexedImage(i), 0, 0)
Next

If you later modify the pictures in the array and want to recreate it as an image, you can do so using the constructor like this:

// Recreate the image from the component pictures
p = New Picture(MyImageSet.Width, MyImageSet.Height, pics)