Scaling dragged image to ImageWell

[code] dim pPictureIn As Picture
dim iWidthIn As Integer
dim iHeightIn As Integer
dim pPictureOut As Picture

If Obj.PictureAvailable then
pPictureIn = obj.Picture
iWidthIn = pPictureIn.Width
iHeightIn = pPictureIn.Height
pPictureOut = me.DrawPicture ( pPictureIn as Picture, 0, 0, 100, 100, 0, 0, iWidthIn, iHeightIn)
Me.Image=Obj.Picture
elseif Obj.FolderItemAvailable then
Me.Image=Picture.Open(obj.FolderItem)
End if
[/code]

The above code is in the DropObject event of an ImageWell. I want to drag/drop a jpeg of unknown size into the ImageWell and have it resized to 100x100 pixels. Could someone please tell me where my error is - I get a syntax error on the pPictureOut=me.drawpicture… line

thanks,
bill

In your code, “me” is the imagewell. As such, it has no DrawPicture method. What you need is a Graphics object. To get that you must first create pPictureOut and then acquire its Graphics property.

pPictureOut = New Picture(100, 100)
pPictureOut.Graphics.DrawPicture(pPictureIn, 0, 0, 100, 100, 0, 0, iWidthIn, iHeightIn)
me.Imabe = pPictureOut

OK thanks Tim!!!


//CODE FROM DROPOBJECT OF IMAGEWELL:

  dim pPictureIn  As Picture
  dim iWidthIn    As Integer
  dim iHeightIn   As Integer
  dim pPictureOut As Picture
  
  If Obj.PictureAvailable then
    pPictureIn  = obj.Picture
  elseif Obj.FolderItemAvailable then
    pPictureIn = Picture.Open(obj.FolderItem)
  End if
  
  iWidthIn    = pPictureIn.Width
  iHeightIn   = pPictureIn.Height
  pPictureOut = New Picture(100, 100)
  pPictureOut.Graphics.DrawPicture(pPictureIn, 0, 0, 100, 100, 0, 0, iWidthIn, iHeightIn)
  
  me.Image  = pPictureOut
  me.Width  = 100
  me.Height = 100

//CODE FROM ADDIMAGE BUTTON ACTION EVENT
  dim pPictureIn  As Picture
  dim iWidthIn    As Integer
  dim iHeightIn   As Integer
  dim pPictureOut As Picture
  
  pPictureIn  = PlunkettPhoto
  iWidthIn  = pPictureIn.Width
  iHeightIn = pPictureIn.Height
  pPictureOut = New Picture(100, 100)
  pPictureOut.Graphics.DrawPicture(pPictureIn, 0, 0, 100, 100, 0, 0, iWidthIn, iHeightIn)
  iwImage.Image = pPictureOut
  

I place the image I have been using to test into the resources of the project (named plunkettphoto). If I use the AddImage button to place the resource file into the imagewell it works perfectly - image is scaled and displayed correctly.

The exact same code in the DropObject event of the ImageWell (when the original jpeg from the desktop is dragged to the same ImageWell) doesn’t scale the image - or at least it doesn’t display the scaled image after the action is complete.

As I use the debugger to step through the DropObject event, everything appears to work correctly. pPictureOut is scaled properly and when the contents of the picture of pPictureOut is examined in the debugger it is scaled properly and not cropped. But when the event completes the image displayed in the ImageWell is original size and cropped.

Someone Help, Tim, can you help me again!

thanks
bill

Hi Bill,

did you solve the problem? I have the same “problem”. I don’t fully understand what happens on drag & drop. I think I miss an event like “paint” that does reset my picture… Is there anybody with a helping hand? Thanks a lot!

Best regards
Peter

Yes, the code show above solved the problem…

For Cocoa (Mavericks, Xojo 2013r3.3) builds the Imagewell momentarily displays the correctly scaled picture but then displays the unscaled picture.

See bug report 27149 - Cocoa ImageWell automatically adds the image to the well when dragging over.

As the bug report suggests it you move the “iwImage.Image = pPictureOut” into a timer you can work around the problem.