Problem with Drop Object on a Canvas

I have 2 apps that use the exact same code to drop an object on a canvas - one works and the other gets a nil object exception.

I literally copied and pasted the Canvas from the app that works to the app that doesn’t. And I copied and pasted the ‘ResizeToFit’ method from the app that works to the one that doesn’t.

I can drag a jpg file from the desktop and drop it on the canvas and everything works perfectly on one app. I can do the same image drop on the other and it gets the exception.

Heres the code copied from the app that DOES NOT WORK:

The nil exception is on the line indicated by *** get the nil exception here —> near the bottom of the ResizeToFit Method.

The open event for the canvas:

Sub Open() Handles Open
End Sub

The DropObject for the canvas:

[code]Sub DropObject(obj As DragItem, action As Integer) Handles DropObject
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)

If bEditCheckStatus Then
End If


End Sub

The ResizeToFit Method:

[code]Private Function ResizeToFit(p As Picture, maxWidth As Integer, maxheight As Integer) as Picture
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 )
*** get the nil exception here —> newPict.Graphics.DrawPicture( p, 0, 0, newPict.Width, newPict.Height, 0, 0, p.Width, p.Height )

Return newPict

End Function

The only thing that could be nil on that line is newPict. Check the values of useWidth and useHeight to make sure they are sane. Also, check that p.Depth is reasonable.

from the debug screen after the exception:
p as Picture
Depth 0
Graphics Nil
HasAlphaChannel True
Height 225
HorizontalResolution 72
ImageCount 0
Objects nil
Transparent 0
Type ImmutableBitmap = 3
VerticalResolution 72
Width 225

even though it says that Graphics and Objects are Nil, if I click on Contents, it displays the proper image.

In the app that works, the Depth is 32 and Graphics is not nil, objects is nil, HasAlphaChannel is False and the type is ImmutableBitmap = 2.

I am dropping the SAME jpg file from my desktop to both apps. The canvas and the method are copied and pasted from the app that works to the one that doesn’t. And the FileTypes1 was also copied and pasted. the image in the first message is supposed to be the FileTypes display…

What do I need to look at the see why the parameters would be different in the 2 applications?

Wild guess: does the second app have hidpi turned on?

Tim my friend, if you’re going the Xojo XDC I owe you a drink.

the app that worked had it turned off, the one that didn’t had it turned on (why I can’t remember) but I turned it off and it worked fine.

Thank you Tim!