Resize picture to a ImageWell

  1. 5 years ago

    How do I resize a picture to fit in a ImageWell ? I want to drag the picture - at the same time - resize it to fit.

  2. Any suggestion on how to do it ? If I move to a Canvas, I will be able to resize it ?

  3. Alex v

    16 Jun 2013 Pre-Release Testers, Xojo Pro Europe, Switzerland
    Edited 5 years ago

    Have a look at the Graphics class :-)

  4. Eduardo G

    16 Jun 2013 Pre-Release Testers Europe (Madrid, Spain)

    As mentioned, your best (and possibly only) bet is to go after the Paint event and resize the image when you have it with graphics.drawpicture

    The logic that handles the drag/drop and the paint refresh you'll also need to take care about.

  5. Sam R

    16 Jun 2013 Pre-Release Testers, Xojo Pro Hengchun, Pingtung, Taiwan

    On Cocoa, you can get the OS to do it for you. Put this code in the Open event of an ImageWell.

     // - (void)setImageScaling:(NSImageScaling)scaling
      declare sub setImageScaling lib "Cocoa" selector "setImageScaling:" ( handle as integer, value as integer )
      setImageScaling( me.handle, 0 )
  6. Eugene D

    16 Jun 2013 Pre-Release Testers, Xojo Pro Canada scispec.ca

    Hello,

    I have an example for a Canvas in a Real Studio project at Click Here . Not sure if this is adaptable to an imagewell for Xojo, and it is worth a try. :)

    Sincerely,

    Eugene

  7. David C

    17 Jun 2013 Pre-Release Testers, Xojo Pro Derby, ITM

    MBS has a wonderful routine (Picture.ScaleImageAndMaskMBS(…)) that can resize the image, mask out the white space and even perform anti-alias smoothing in one line! It is cross-platform too.

  8. How I do this ? I want to drop a picture to a canvas and refresh it. When I drop, I will resize the image.

    I am putting the below in the Canvas DropObj picture, but I am getting an issue when I resize it.

    I have mImage defined as a Property. When I have the Open event of the Canvas, I know it is resizing correctly. A "blank" picture is showing correctly.

    //DropObj
    mImage = obj.Picture
    Me.Invalidate

    In the Paint event of the Canvas I have this:
    g.DrawPicture(mImage, 0,0, g.Width, g.Height, 0,0,mImage.Width, mImage.Height)

    And I am getting a NIL exception ....

  9. Mike C

    20 Jun 2013 Pre-Release Testers, Xojo Pro North Carolina (USA)
    Edited 5 years ago

    See the "ObjectsInCanvas" example application that comes with Real Studio / Xojo. This helped me get started and it sounds like you are heading down the same road. :) Check the code out.

    It doesn't have resize code, but it will help you.

  10. Solved ....

    mImage=Picture.Open(obj.FolderItem)

  11. Richard D

    21 Jun 2013 Pre-Release Testers, Xojo Pro Europe (UK, London)

    @David C MBS has a wonderful routine (Picture.ScaleImageAndMaskMBS(…)) that can resize the image, mask out the white space and even perform anti-alias smoothing in one line! It is cross-platform too.

    i used that function a lot my all my application

  12. mImage=Picture.Open(obj.FolderItem) by itself does not resize picture to a ImageWell, would you mind posting the complete code?
    Thanks.
    Lennox

  13. Here it is.

    Defined mImage in the Properties of the Window as Picture. Also set the FileTypes to handle jpeg in the App.

    For the Canvas, defined for the Events:

    DropObject:

    If Obj.PictureAvailable then
    mImage=obj.picture
    Elseif Obj.FolderItemAvailable then
    mImage=Picture.Open(obj.FolderItem)
    End if

    Me.Invalidate

    Open:

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

    mImage=EmBranco <= this is the "blank"/ standard picture when the Canvas open.

    Paint:

    // This is the resize
    g.DrawPicture(mImage, 0,0, g.Width, g.Height, 0,0,mImage.Width, mImage.Height)

    // The below is just a rectangle around the frame
    g.ForeColor = &cA1CBFF
    g.DrawRect( 0, 0, g.Width, g.Height )

  14. Also please see the "DragPicture" example that comes with XOJO.

  15. 4 years ago

    Axel S

    is not verified 13 Feb 2015 Europe (Germany, Erfurt)

    @Sam R On Cocoa, you can get the OS to do it for you. Put this code in the Open event of an ImageWell.
    // - (void)setImageScaling:(NSImageScaling)scaling declare sub setImageScaling lib "Cocoa" selector "setImageScaling:" ( handle as integer, value as integer ) setImageScaling( me.handle, 0 )

    with this in Open - ImageWell handles Drop automatically and you can use Cut, Copy, Paste, Delete from the Edit Menu

      declare sub setEditable lib "Cocoa" selector "setEditable:" _
      ( handle as integer, value as Boolean )
      setEditable( me.handle, true )

    Example ImageWell

  16. 3 years ago

    Tim P

    14 Jan 2016 Pre-Release Testers feedback://46303

    @Axel S with this in Open - ImageWell handles Drop automatically and you can use Cut, Copy, Paste, Delete from the Edit Menu

      declare sub setEditable lib "Cocoa" selector "setEditable:" _
      ( handle as integer, value as Boolean )
      setEditable( me.handle, true )

    Expanding on that how might one detect a change to the ImageWell when a user Pastes?

  17. 4 weeks ago

    Lennox J

    Nov 15 Jamaica. West Indies

    @Eugene D Hello,

    I have an example for a Canvas in a Real Studio project at Click Here . Not sure if this is adaptable to an imagewell for Xojo, and it is worth a try. :)

    Sincerely,

    Eugene

    Hi Eugene,

    Could you please upload that file again.

    Thanks.

    Lennox

  18. Vigia L

    Nov 15 Pre-Release Testers, Xojo Pro

    ImageWell1.picture = ReSizeImage(pic,ImageWell1.width,ImageWell1.Height)

    fuction ReSizeImage (Pic as Picture,SetWidth As Integer=240,SetHeight As Integer=320) as picture
    If pic = Nil Then Return Nil
    Dim Width,Height As Integer
    Dim imageWidth As Integer = pic.Width
    Dim ImageHeight as Integer = pic.Height
    
    if(setWidth/imageWidth<=setHeight/imageHeight) then
      width=imageWidth*(setWidth/imageWidth)
      height=imageHeight*(setWidth/imageWidth) 
    else
      Width=imageWidth*(setHeight/imageHeight)
      Height=imageHeight*(setHeight/imageHeight)
    end if
    
    Dim NewSizePic as new Picture(Width,Height,32)
    NewSizePic.Graphics.DrawPicture(Pic, 0, 0, Width, Height, 0, 0, pic.Width, pic.Height)
    Return NewSizePic
    end fuction
  19. Lennox J

    Nov 15 Jamaica. West Indies

    Thanks,
    I'll try it.
    Lennox

  20. Eugene D

    Nov 15 Pre-Release Testers, Xojo Pro Canada scispec.ca

    @Lennox J Hi Eugene,

    Could you please upload that file again.

    Thanks.

    Lennox

    I will post it when i am back on my developer computer in a day or two. :)

  21. Newer ›

or Sign Up to reply!