B4A Library [Library] RSCrop - Crop images with gallery

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.b4x.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:

B4X:
Sub mnuCrop_Click
Dim CropImage As RSCrop
CropImage.Initialize("CropImage", "image.jpg")
CropImage.CropImage2(True, False, False, False)
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

  • RSCrop
    Permissions:
    • android.permission.WRITE_SECURE_SETTINGS
    • android.permission.READ_PHONE_STATE
    Methods:
    • Initialize (EventName As String, FileName As String)
      Initializes the RSCrop Library.
      EventName - Events subs prefix.
      Events: "Cropped (Success As Boolean, Path as String)"
    • cropImage (aspectX As Int, aspectY As Int, outputX As Int, outputY As Int, scale As Boolean, return_data As Boolean, faceDetection As Boolean, circleCrop As Boolean)
      Crops an image with the standard media gallery.
      aspectX: - Set this to define the X aspect ratio of the shape
      aspectY: - Set this to define the Y aspect ratio of the shape
      outputX: - Set this to define the max size of the output bitmap
      outputY: - Set this to define the max size of the output bitmap
      scale: - should it scale
      return_data: - Return the bitmap with Action=inline-data by using the data
      faceDetection:
      circleCrop: - if this string is not null, it will provide some circular crop
    • cropImage2 (scale As Boolean, return_data As Boolean, faceDetection As Boolean, circleCrop As Boolean)
      Crops an image with the standard media gallery.
      Difference is that you can use a rectangular crop with this.
      scale: - should it scale
      return_data: - Return the bitmap with Action=inline-data by using the data
      faceDetection:
      circleCrop: - if this string is not null, it will provide some circular crop
    • cropImage3 (scale As Boolean, return_data As Boolean, faceDetection As Boolean, circleCrop As Boolean, btmp As Bitmap)
      Crops an image with the standard media gallery.
      Difference is that you can preselect a bitmap with this.
      scale: - should it scale
      return_data: - Return the bitmap with Action=inline-data by using the data
      faceDetection:
      circleCrop: - if this string is not null, it will provide some circular crop

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 ;)
 

Attachments

  • RSCrop.zip
    4.8 KB · Views: 1,217
Last edited:

Luiz Fernando Orlandini

Active Member
Licensed User
Longtime User
Hello folks.

I'm trying to use this lib with B4A 6.0 and getting the attached exception which crash my App, when I try to open a new Activity.
 

Attachments

  • Screen Shot 2016-07-04 at 12.40.37 AM.png
    Screen Shot 2016-07-04 at 12.40.37 AM.png
    152.7 KB · Views: 210

Mashiane

Expert
Licensed User
Longtime User
THis is
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.b4x.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:

B4X:
Sub mnuCrop_Click
Dim CropImage As RSCrop
CropImage.Initialize("CropImage", "image.jpg")
CropImage.CropImage2(True, False, False, False)
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 ;)
This is so perferct!!
 

iCAB

Well-Known Member
Licensed User
Longtime User
Hi Guys

The last parameter in this line shows CircleCrop

B4X:
CropImage.CropImage2(True, True, False, True)

Did anyone get it to work as circleCrop

Thanks in advance
 

ykucuk

Well-Known Member
Licensed User
Longtime User
I tried with Samsung Galaxy S5 and Samsung Note 5.

The application asks me 2 times for select image and shows dialog after the second select.

Note5 never shows me crop dialog and Galaxy 5 show.

Any help?
 
Top