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)
Return
[/code]
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
Else
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
[/code]
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 isnt 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 isnt working
newPict newPict
[/b]
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