Resize picture to a ImageWell

  1. ‹ Older
  2. 5 years ago

    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 )
  3. 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

  4. 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.

  5. 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 ....

  6. 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.

  7. Solved ....

    mImage=Picture.Open(obj.FolderItem)

  8. 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

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

  10. 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 )

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

  12. 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

  13. 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?

  14. 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

  15. 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
  16. Lennox J

    Nov 15 Jamaica. West Indies

    Thanks,
    I'll try it.
    Lennox

  17. 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. :)

  18. Lennox J

    Nov 16 Jamaica. West Indies

    Thanks Eugene,

    Lennox

  19. Lennox J

    Nov 16 Jamaica. West Indies

    Thanks Vigia Lin,

    This is what I really wanted... When a .jpg is dropped on to a canvas it automatically fits the canvas size. Works great.

    Thanks again.

    Lennox

  20. Eugene D

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

    @Lennox J Hi Eugene,

    Could you please upload that file again.

    Thanks.

    Lennox

    ResizePic Example

  21. Lennox J

    Nov 17 Jamaica. West Indies

    Thanks Eugene,

    Works great,

    Thanks again.

    Lennox

or Sign Up to reply!