Picture.Graphics is Nil?


I open a picture on my computer, and want to access the graphics. The picture is not nil, but the graphics are Nil. How is this possible?

[code] Dim picFile As FolderItem
picFile = GetOpenFolderItem()

If picFile <> Nil Then
Dim pic As Picture
pic = Picture.Open(picFile)

pic = ModernizePicture(pic)

pic.Graphics.ForeColor = &cFFFFFF
pic.Graphics.TextUnit = FontUnits.Pixel
pic.Graphics.TextSize = 50[/code]

some pictures are read only and than graphics is nil.

Just tested, picFile.IsWriteable returns true.

What does “ModernizePicture” do? Can you post the Code please?


It was the ModernizePicture function from this page: http://documentation.xojo.com/index.php/Picture

But I found out what was wrong. It had something to do with HiDPI support.

ModernizePicture was:

[code] If input.hasAlphaChannel Then Return input

Dim result As New Picture( input.Width, input.Height )
result.HorizontalResolution = input.HorizontalResolution
result.VerticalResolution = input.VerticalResolution
result.Graphics.DrawPicture( input, 0, 0 )
Return result[/code]

I deleted the first line, now it ALWAYS makes a new copy of the image. Now it works. I totally don’t understand why an image would be immutable because of HiDPI, but apparently, it is.

Read here: http://blog.xojo.com/2016/04/05/xojo-retinahidpi-the-journey-of-a-thousand-pixels/

Thanks for thinking with me!