B4A Library CropImageView V1.0

CropImageView
Version:
1

This is a wrapper for this GitHub Project.

CropImageView001.png


  • CropImageView
    Fields:
    • ba As BA
    Methods:
    • AddToParent (Parent As ViewGroup, left As Int, top As Int, width As Int, height As Int)
    • BringToFront
    • DesignerCreateView (base As PanelWrapper, lw As LabelWrapper, props As Map)
    • Initialize (EventName As String)
    • Invalidate
    • Invalidate2 (arg0 As Rect)
    • Invalidate3 (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • IsInitialized As Boolean
    • RemoveView
    • RequestFocus As Boolean
    • SendToBack
    • SetBackgroundImage (arg0 As Bitmap)
    • SetColorAnimated (arg0 As Int, arg1 As Int, arg2 As Int)
    • SetLayout (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • SetLayoutAnimated (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int, arg4 As Int)
    • SetVisibleAnimated (arg0 As Int, arg1 As Boolean)
    • rotateImage (degrees As Int)
      Rotates image by the specified number of degrees clockwise. Cycles from 0 to 360
      degrees.
    • setAspectRatio (aspectRatioX As Int, aspectRatioY As Int)
      Sets the both the X and Y values of the aspectRatio.
    Properties:
    • ActualCropRect As RectF [read only]
      Gets the crop window's position relative to the source Bitmap (not the image
      displayed in the CropImageView).
    • Background As Drawable
    • Color As Int [write only]
    • CroppedImage As Bitmap [read only]
      Gets the cropped image based on the current crop window.
    • Enabled As Boolean
    • FixedAspectRatio As Boolean [write only]
      Sets whether the aspect ratio is fixed or not; true fixes the aspect ratio, while
      false allows it to be changed.
    • Guidelines As Int [write only]
      Sets the guidelines for the CropOverlayView to be either on, off, or to show when
      resizing the application.
    • Height As Int
    • ImageBitmap As Bitmap [write only]
      Sets a Bitmap as the content of the CropImageView.
    • Left As Int
    • Tag As Object
    • Top As Int
    • Visible As Boolean
    • Width As Int

This library is Donationware. You can download the library, you can test the library. But if you want to USE the library in your App you need to Donate for it.
Please click here to donate (You can donate any amount you want to donate for the library (or my work) :)
 

Attachments

  • CroppedImageViewEx.zip
    74.3 KB · Views: 934
  • libCropImageView1.0.0.zip
    27.1 KB · Views: 942
Last edited:

Rusty

Well-Known Member
Licensed User
Longtime User
Hi Don,
I am using your crop library (which works great) but I am combining it with CameraEX.
I want to take a photo, save it to a file, then allow the user to crop it and save it.
when I combine the two:
  • CameraEx takes the photo and saves it
  • I then startactivity(crop), which is your demo
  • when the LoadLayout("Layout1") executes, I get
** Activity (main) Create, isFirst = true **
automode false
** Activity (main) Resume **
Continuous focus mode is not available
[Height=480, IsInitialized=false, Width=640
]
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (crop) Create, isFirst = true **
Error occurred on line: 19 (Crop)
android.content.res.Resources$NotFoundException: Resource ID #0x0
at android.content.res.Resources.getValue(Resources.java:1166)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2395)
at android.content.res.Resources.getLayout(Resources.java:982)
at android.view.LayoutInflater.inflate(LayoutInflater.java:395)
at com.edmodo.cropper.CropImageView.init(CropImageView.java:473)
at com.edmodo.cropper.CropImageView.<init>(CropImageView.java:78)
at de.donmanfred.CropImageViewWrapper._initialize(CropImageViewWrapper.java:56)
at de.donmanfred.CropImageViewWrapper.Initialize(CropImageViewWrapper.java:49)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:753)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:343)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at b4a.example.crop.afterFirstLayout(crop.java:102)
at b4a.example.crop.access$000(crop.java:17)
at b4a.example.crop$WaitForLayout.run(crop.java:80)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:149)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:610)
at dalvik.system.NativeStart.main(Native Method)
** Activity (crop) Resume **

Line 19 is:
B4X:
Sub Activity_Create(FirstTime As Boolean)
 LINE 19 >>---->   Activity.LoadLayout("layout1")
                            
End Sub
any ideas what is in the Layout1 (your original layout) that might be causing this?
Thanks Rusty
 

Rusty

Well-Known Member
Licensed User
Longtime User
B4X:
Sub btnCrop_Click
    camEx.CloseNow
    camEx.Release
    StartActivity(Crop)
End Sub
This is the code calling the startactivity(crop)
 

Rusty

Well-Known Member
Licensed User
Longtime User
I moved it to a new sub and called callsubplus and waited 1000ms
B4X:
Sub btnCrop_Click
    camEx.CloseNow
    camEx.Release
    Dim callPlus As CallSubPlus
    callPlus.Initialize
    callPlus.CallSubPlus(Me, StartAct, 1000)
End Sub

Sub StartAct
    StartActivity(Crop)
End Sub
Still no happiness.
I have even tried removing the civ from the layout1.bal file and adding it in code, but it dies on that too...
Thanks ,
 

Rusty

Well-Known Member
Licensed User
Longtime User
I looked at the Module attributes and I must have overlaid the #AdditionalRes: ..\resources
I added that back and now it seems to load
Sorry to waste your time :(
Thanks for the help.
Rusty
 

Rusty

Well-Known Member
Licensed User
Longtime User
Hi Don,
Your class works great :)
Is there a way to move the crop rectangle to a specific x, y coordinate (as center)?
Thanks
Rusty
 

Rusty

Well-Known Member
Licensed User
Longtime User
Thanks Don!
Can the background image be moved behind the rectangle to center it appropriately?
 
Top