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:
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
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:Methods:
- android.permission.WRITE_SECURE_SETTINGS
- android.permission.READ_PHONE_STATE
- 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
Last edited: