B4A Library [Library] RSCrop - Crop images with gallery

Discussion in 'Additional libraries, classes and official updates' started by XverhelstX, Jul 27, 2012.

  1. XverhelstX

    XverhelstX Well-Known Member Licensed User

    Hey everyone,

    For an app i'm developing, I needed to let the user crop a piece of a bitmap to use in my app.
    I stumbled on this thread: http://www.basic4ppc.com/forum/basic4android-updates-questions/19550-resize-crop.html
    but it lacked some features like pinching, rectangular cropping, resizing, zoom and panning and more.

    After some googling, i figured out that you could send an intent to the default media gallery to let it crop your images.

    It opens your gallery where you select your image and then the cropping activity opens. After the cropping is done, an event is raised with the Path and a success boolean.
    3 Functions are needed to get you going:

    Code:
    Sub mnuCrop_Click
    Dim CropImage As RSCrop
    CropImage.Initialize(
    "CropImage""image.jpg")
    CropImage.CropImage2(
    TrueFalseFalseFalse)
    End Sub

    Sub CropImage_Cropped (Success As Boolean, Pathname As String)
       
    If Success = True Then
          
    ToastMessageShow("Successfully cropped!"True)
          
    ToastMessageShow("Path: " & Pathname, True)
       
    Else
          
    ToastMessageShow(Pathname, False)
       
    End If
    End Sub
    After the cropping is done, the image is saved to your file.dirExternal and the filename is the one you specified in your initialize method.

    Regards,
    Tomas

    Edit: If people would like to test:
    I would like to know on which devices this work: API level (android version) and phone
    Preferably I need Galaxy Note support ;)
     

    Attached Files:

    Last edited: Jul 27, 2012
  2. NJDude

    NJDude Expert Licensed User

    Awesome!!!
     
  3. vb1992

    vb1992 Well-Known Member Licensed User

    So no pinching (pinch zoom), or face detection here?

    :D
     
  4. XverhelstX

    XverhelstX Well-Known Member Licensed User

    There's face detection, no pinching however i think.

    Tomas
     
  5. vb1992

    vb1992 Well-Known Member Licensed User

    I couldn't get the face detection working?
    or maybe I just don't know what it does when set to true...?

    I would assume it highlights a face? or zooms into the face detected

    I am on 2.3 gingerbread
     
  6. XverhelstX

    XverhelstX Well-Known Member Licensed User

  7. vb1992

    vb1992 Well-Known Member Licensed User

    Save/Discard buttons are not visible on my Galaxy 10.1 tablet
     
  8. XverhelstX

    XverhelstX Well-Known Member Licensed User

    Last edited: Jul 27, 2012
  9. vb1992

    vb1992 Well-Known Member Licensed User

    That was weird, i just tested again, and face detection found 3 faces
    so that works on images that have faces that are detectable, the
    previous test, was with faces that were too small i believe.

    Now I found the check mark / OK
    in the top right hand corner instead of the buttons.

    I click OK and it keeps spinning on "saving picture"
     
  10. NJDude

    NJDude Expert Licensed User

    Ok, I tried your lib using only the sample code you posted:

    1- HTC EVO - Froyo = Works
    2- Nexus 7 - Jelly Bean = Works
    3- HTC EVO LTE - ICS = Works
    4- Chinese Tab - Froyo = Works
    5- Galaxy Tab 10.1 - HC = Doesn't work (same issue as described by vb1992 above)

    Maybe Samsung doesn't like your lib :D
     
    Last edited: Jul 27, 2012
  11. vb1992

    vb1992 Well-Known Member Licensed User

    How would we get this to work on the Galaxy Tab 10.1?
    Maybe that would do it.
     
  12. synapse

    synapse Member Licensed User

    Does the library allow one to specify a particular image to be passed in cropimage, rather than just opening a gallery please? I see you can specify the output image...
     
  13. DonManfred

    DonManfred Expert Licensed User

    I have made a little example and have tested it on my Galaxy Note 3 - Phone
    Facturer: Samsung
    Model: SM-N9005
    Android: 4.3

    and i got two Toastmessages after croppting an image...
    Successfully cropped
    and
    Path /storage/emulated/0/image.jpg

    But HOW can i copy this file to a place where i can find it if my phone is connected to pc?
    Sorry, i´m not familar which "such problems" :)
     
  14. synapse

    synapse Member Licensed User

    I changed the output filename to include the path from root....
     
  15. systems1

    systems1 Member Licensed User

    Hi XverhelstX

    Great work, I have tested this library in many devices including Samsung, HTC, Sony and others. It's working well in almost all devices.

    I want to fix the size of cropping image. I mean i want to fix height and width for the image. I have got max height and width limit for image to be cropped. So it should not allow me to crop above that limit.
    How can i do this...?

    Thanks in advance
     
  16. DonManfred

    DonManfred Expert Licensed User

    You can limit yourself :)
    Code:
    If ImageWidth < LimitedWidth then
      
    If ImageHeight < LimitedHeight then
        
    ' Put your crapping code here ;-)
      end if
    end if
     
    alwaysbusy likes this.
  17. systems1

    systems1 Member Licensed User

    Hi DonManfred,

    Thanks for the reply
    But how can i get the ImageWidth and ImageHeight of image. I can assign some value to LimitedWidth and LimitedHeight.
    But how can i get the value of ImageWidth and ImageHeight. Because it is getting the value from the library right...

    what i want to do is this,
    when i open some image from gallery and drag the four corners to fix the height and width to crop the image, here i want to fix max width and height. It should not allow me to drag and select the image more than what i specified in LimitedWidth and LimitedHeight

    Thanks
     
    Last edited: Jan 23, 2014
  18. boten

    boten Active Member Licensed User

    I like this lib a lot. One question:
    When calling CropImage I get a menu to select which app to use for cropping. Gallery is only one option. Other options include, for example, Astro file manager.
    I want to use ONLY gallery, without displaying the selection menu.
    How is this possible? - so that when CropImage is called it will automatically open the image in Gallery instead of giving the user a selection.
     
  19. Douglas Farias

    Douglas Farias Expert Licensed User

    how to use retun_data can explain me?

    and

    if i dont have sd card? how can i change file.dirExternal to internal?
     
    Last edited: Apr 14, 2014
  20. coslad

    coslad Well-Known Member Licensed User

    Hi ,

    i'm trying to use this library , but when the crop function start , it asks to complete the action with the gallery twice ,it's annoying thing , i tried on a galaxy note 3 and a galaxy s , any idea ?
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice