Resized ImageWell picture won't stay resized

I’m trying to learn how to put a picture into an ImageWell.

On a new project I have placed ImageWell1 and Canvas1 objects.

I have performed SetFileTypes to setup file types for jpg and png files.

In the ImageWell Open action I have:
Me.AcceptPictureDrop
me.AcceptFileDrop(“image/jpeg”)
me.AcceptFileDrop(“image/png”)

In the ImageWell MouseDown action I have:

[code] Dim Myfile As FolderItem
Dim MyPicture As Picture
Dim resized as new picture( 200, 250 )

if IsContextualClick then
me.image = EmptyPic
return false
end

Myfile = GetOpenFolderItem(“image/png;image/jpeg”)
if MyFile <> nil then
MyPicture=Picture.Open(Myfile)
resized.graphics.drawpicture (MyPicture, 0, 0, 200, 250, 0, 0, MyPicture.width, MyPicture.height)
me.image = resized
end[/code]

So far so good. All of this works perfectly. I can click on the ImageWell and a file requester lets me choose a picture and it reads the picture and resizes it perfectly.

The problem comes in the DropObject action.

[code] Dim MyPicture As Picture
Dim resized as new picture( 200, 250 )

If Obj.PictureAvailable then
''me.image = Obj.Picture
'MyPicture = Obj.Picture
'me.DrawInto(MyPicture.Graphics,0,0)
'resized.graphics.drawpicture MyPicture, 0, 0, 200, 250, 0, 0, MyPicture.width, MyPicture.height
'me.image = resized
elseif Obj.FolderItemAvailable then
MyPicture = Picture.Open(obj.FolderItem)
resized.graphics.drawpicture (MyPicture, 0, 0, 200, 250, 0, 0, MyPicture.width, MyPicture.height)
me.image = resized
Canvas1.backdrop = resized
MsgBox(“folder item received”)
End if
[/code]

The problem is that when the MsgBox appears the picture in the ImageWell is perfect. Properly resized. And the picture in the Canvas shows properly resized.

But when I dismiss the MsgBox the picture in the ImageWell shows the picture hugely blown up (in its original size) as if it were being dropped into the ImageWell without being resized … but, of course, the picture in the Canvas still displays properly resized.

WHAT is causing it to revert to the non-resized picture?!?!?!

try this

put this OUTSIDE the event (so it is a global variable…)

 Dim resized as  picture

put THIS in your event

resized = new picture( 200, 250 )

this will keep resized in scope, the Msgbox takes focus away, and when it returns the validiaty of “resized” may have changed… this MIGHT (repeat MIGHT) cause that not to happen… just off the top of my head

OK, I tried that and now I get a NilObjectException

Sorry, I forgot to put the "Resized = New Picture(200,250) inside the event.

After doing that … it still behaves the same way. While paused for the MsgBox the picture is properly resized, but after dismissing the MsgBox it reverts to full sized.

BTW I’ve tried taking the MsgBox out and it just goes to ‘full sized image’ immediately.

<https://xojo.com/issue/27149>
The problem is that after the DropObject event some automatic handling is adding the original picture.
Simply put me.AcceptFileDrop("") in an ImageWells Open event and the Drop is handled.

Fortunately it’s reported as fixed and could be in the next update. …or did I misread ??

A workaround is to put a Canvas over the ImageWell, handle the drop there but assign the picture to the well.

The ImageWell Open event already looks like this:

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

So that’s not the problem

I hope it IS in the next update but I’m running the latest version now (2015 r4) and I need to solve this problem NOW because I need this program working within the next week. I’m using it in a Pinewood Derby program and I want to be able to show the boy’s pictures in their registration and I have a race to run next week.

If you’re using OS X, you can declares to get the ImageWell to scale the image up/down to fit with. So you don’t even need to resize the image.

https://forum.xojo.com/conversation/post/14665

Axel … I looked at that post and with my absolute zero knowledge of Cocoa programming I have no idea what that stuff even means, let alone how to implement it.

Sam … you have my attention but what does “you can declares” mean? I can declare WHAT?

Tim … I’ll play with the idea of laying a canvas over the imageWell and see if I can make that work.

[quote=241227:@Marc Speth]Axel … I looked at that post and with my absolute zero knowledge of Cocoa programming I have no idea what that stuff even means, let alone how to implement it.

Sam … you have my attention but what does “you can declares” mean? I can declare WHAT?[/quote]
Axel linked to the declare Sam mentioned. Declares can be confusing, but this one is easy - just copy and paste it into the ImageWell.Open event.

Ah a declare newbie, ‘Declares’ are means of digging into the OS X toolbox, as Xojo uses the same the same controls as Objective-C and swift, you can adapt the code to work within Xojo.

Indeed he did, but I’ll try to explain a bit better.

// - (void)setImageScaling:(NSImageScaling)scaling declare sub setImageScaling lib "Cocoa" selector "setImageScaling:" ( handle as integer, value as integer ) setImageScaling( me.handle, 0 )
So the OS X function ‘setImageScaling’ is what is used to adjust how the ImageWell performs scaling, it takes a single parameter and that’s the scaling method. It doesn’t return anything (void), so it’s a subroutine, rather than a function.

However we still need to specify which object to send the message to and that’s where the Xojo ‘.handle’ property comes into effect.

I don’t have a clue HOW that works but it works like a charm! Thank you!

It functionality built into the Mac OS system, while Xojo doesn’t have an option for it, using a declare you can tap into the system and manipulate the control.

Once you get more accustomed with declares, it’s how you can take your Xojo applications to the next level :slight_smile: