picture.graphics property is nil

Found a couple of older threads that looked promising from the title but didn’t answer my problem. So here’s the detail:

Mac Pro Late 2013 with macOS 10.12.6 Sierra
Xojo 2017 R3

I have a program that works perfectly that has a canvas I can drop a jpg file onto, it resizes appropriately and displays the image in the canvas.

I have a new program that I want to do the exact same thing so I copy and pasted the Canvas to the new app along with the Resize method and the File Type specification.

The Open event of the canvas contains:

Me.AcceptPictureDrop Me.AcceptFileDrop("image/jpeg")

The DropObject event contains:

[code]Dim pPictureIn As Picture

If Obj.PictureAvailable Then
pPictureIn = obj.Picture
Elseif Obj.FolderItemAvailable Then
pPictureIn = Picture.Open(obj.FolderItem)
End If

Me.backdrop = ResizeToFit(pPictureIn, 135, 175)


There is apparently no problem here because the method that is called (ResizeToFit) receives a picture containing the correct image.

The ResizeToFit method contains:

[code]Dim Hin As Integer
Dim Win As Integer
Dim ratio As Double

Hin = p.Height
Win = p.Width

ratio = Win / Hin

Dim w1 As Integer = maxWidth
Dim h1 As Integer = w1 / ratio

Dim h2 As Integer = maxHeight
Dim w2 As Integer = h2 * ratio

Dim useWidth, useHeight As Integer

If h1 > maxHeight Then
useWidth = w2
useHeight = h2

Elseif w2 > maxWidth Then
useWidth = w1
useHeight = h1

Elseif ( maxHeight - h1 ) < ( maxWidth - w2 ) Then
useWidth = w1
useHeight = h1

useWidth = w2
useHeight = h2

End If

Dim newPict As New Picture( useWidth, useHeight, p.Depth )
newPict.Graphics.DrawPicture( p, 0, 0, newPict.Width, newPict.Height, 0, 0, p.Width, p.Height ) (nil exception here)

Return newPict

Here’s a list of property values for “p” which is the picture passed from the canvas event and for the newPict which should be the resized picture but I get a nil exception

The following values were obtained by dropping the exact same file from the same location onto the 2 different apps.

The original dropped image:

                                    [b]      In app that is working         	In app that isn’t working
                                               p	                                               p	[/b]

Depth 32 0
Graphics graphics nil
HasAlphaChannel false true
Height 350 350
HorizontalResolution 72 72
ImageCount 0 0
Objects nil nil
RGBSurface RGBSurface RGBSurface
Transparent 0 0
Type MutableBitmap = 2 ImmutableBitmap = 3
VerticalResolution 72 72
Width 473 473

what should be the resized imaged:

                               [b]            In app that is working	                In app that isn’t working
                                                     newPict	                                       newPict

Depth 32 0
Graphics graphics nil
HasAlphaChannel false false
Height 99 99
HorizontalResolution 72 72
ImageCount 0 0
Objects nil Group2D
RGBSurface RGBSurface nil
Transparent 0 0
Type MutableBitmap = 2 Vector = 1
VerticalResolution 72 72
Width 135 135

sorry but the forum software reformatted my values list. In any case the 1st value after the property name is the working app and the second is the non-working app.

Try turning off the Supports HiDPI Shared Setting.

Don’t set the depth when creating a new picture.

Dim destination as new picture( destWidth, destHeight )

For 90% of HiDPI drawing you can forget that you do HiDPI. Here things become a bit more complicated. You need to create a mutable picture out of an immutable one. See http://docs.xojo.com/index.php/Picture.CopyColorChannels .

Based on the properties, my money is on this:

Objects nil Group2D
Type MutableBitmap = 2 Vector = 1

Im guessing this image has no bitmap component, just some drawing instructions, so there is no picture to copy?
But Beatrix’s idea looks worth a try.

Another possibility… what are useWidth and UseHeight? It’s possible that initialization of newPict failed outright.

Always know I will get an answer here. Thanks everyone. I simply turned off the Supports HiDPI and it worked perfectly.

thanks again.