Help please: Saving a part of an image in canvas

Hello I have an image displayed on a canvas and

I have this in the MouseDown event
app.gMousedownXD = X
app.gMousedownyD = Y

and this in the MouseDown event
app.gMouseUpXU = X
app.gMouseUpYU = Y

Canvas1.Graphics.ForeColor = &cFF0000
Canvas1.Graphics.DrawRect ( app.gMousedownXD, app.gMousedownYD, app.gMouseUpXU-app.gMousedownXD, app.gMouseUpYU-app.gMousedownYD )

Dim p as picture
Dim W, H as Integer
W = app.gMouseUpXU - app.gMousedownXD
H = app.gMouseUpYU-app.gMousedownYD
p = new picture (W, H, 32)

With this I get the picture on the desktop but it is blank,
Dim MyJpg as FolderItem
MyJpg = SpecialFolder.Desktop.Child(“My Jpg.Jpg”)
p.save(MyJpg, Picture.SaveAsJPEG)

What am I missing?

Thanks.

Lennox

you create a black “P” with “new picture”
yet you never put anything in it

Hi Dave thanks,

I now have this in the MouseUp event…

app.gMouseUpXU = X
app.gMouseUpYU = Y


Dim W, H as Integer
W = Abs(app.gMouseUpXU) - Abs(app.gMousedownXD)
H = Abs(app.gMouseUpYU) - Abs(app.gMousedownYD)

If W = 0 or H = 0 then
  
else
  Canvas1.Graphics.ForeColor = &cFF0000
  Canvas1.Graphics.DrawRect (app.gMousedownXD, app.gMousedownYD, W, H )
  
  Dim p as picture
  p = new picture (W, H, 32)
  p.Graphics.DrawPicture (app.DroppedPicture, 0, 0, app.gMouseUpXU, app.gMouseUpYU, app.gMousedownXD, app.gMousedownYD, app.DroppedPicture.Width, app.DroppedPicture.Height  )
  
  Dim MyJpg as FolderItem
  MyJpg = SpecialFolder.Desktop.Child("My Jpg.Jpg")
  p.save(MyJpg, Picture.SaveAsJPEG)
  
  
end if

The width is correct but the height displayed is longer than the selected height, how can I correct that?

Thanks.

Lennox

Hello,

I checked Xojo Graphics.DrawPicture and I got…
Graphics.DrawPicture(Image as Picture, X as Integer, Y as Integer [,DestWidth as Integer ] [, DestHeight as Integer ] [, SourceX as Integer ] [, SourceY as Integer ] [, SourceWidth as Integer ] [, SourceHeight as Integer])

I tried using that information but could not get it to work so I tried…
Graphics.DrawPicture(Image as Picture, X as Integer, Y as Integer [,DestWidth as Integer ] [, DestHeight as Integer ] [, SourceX as Integer ] [, SourceY as Integer ] [, DestWidth as Integer ] [, DestHeight as Integer])

and that seems to work for me,.

Am I doing it correctly?

Lennox