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: 814
  • libCropImageView1.0.0.zip
    27.1 KB · Views: 821
Last edited:

DonManfred

Expert
Licensed User
Longtime User
if i do load another image after cropping one with
B4X:
    Dim b As Bitmap
    b.Initialize(File.DirAssets,"mycats.jpg")
    civ.ImageBitmap = b

the image is shown in crop-tool...
When i crop again i get a cropped image of the new loaded image.

So. It is working for me

Also, some images won't display but will still crop - memory?
maybe you can see additional information in the (unfiltered) log
 

MaFu

Well-Known Member
Licensed User
Longtime User
Great Lib!
One question. Why I cant access all parts of the image (there is some margin and then inside is crop panel). Because maybe I want to crop part of the image that is in some corner.

Thanks

Damn. It seems my message gone lost on server change.

The next version of my MFLib contains a "Cropper" view. This view looks like CropImageView but it's a complete rewrite from scratch for B4A (and not a wrapper). It hasn't the margin problem and a few extras (no resources needed, visible feedback of dragged corner, adjustable colors).
Due to my spare time at the moment (i'm busy with other projects) the new lib will not ready before january.
 

DavideV

Active Member
Licensed User
Longtime User
Hi DonManfred, really great lib.
It could be my mistake but i can't get FixedAspectRatio and SetAspectRatio to work, the first (FixedAspectRatio=true) displays a vertical, fixed crop area non-adjustable and this could be right.
Then i apply the second, say civ.setAspectRatio(50,50), and does nothing.
Also with FixedAspectRatio=false the crop area doesn't change with SetaspectRatio.
Could you please check or post a little example?

My goal is to get a square cropped image

Thx in advance

DavideV
 

kreativa

Member
Licensed User
Longtime User
Hi everybody,
Just a question. Is there a way to define the position and the dimensions of the initial rect, used to crop the image?

Thanks!
 

schalkgreyling

Member
Licensed User
Longtime User
I have the same issue, have you been able to solve it?

Kind Regards
Hi DonManfred, really great lib.

It could be my mistake but i can't get FixedAspectRatio and SetAspectRatio to work, the first (FixedAspectRatio=true) displays a vertical, fixed crop area non-adjustable and this could be right.

Then i apply the second, say civ.setAspectRatio(50,50), and does nothing.

Also with FixedAspectRatio=false the crop area doesn't change with SetaspectRatio.

Could you please check or post a little example?



My goal is to get a square cropped image



Thx in advance



DavideV

Hi DavideV,

I have the same issue, have you been able to solve it?

Kind Regards
 

schalkgreyling

Member
Licensed User
Longtime User
I
Hi schalkgreyling,
unfortunately not :(

Bye

I do the following after choosing an image from library:

B4X:
        Dim b As Bitmap
        b.Initialize("",file_loc)
        CropImageView1.setAspectRatio(5,5)
        CropImageView1.FixedAspectRatio = True
        CropImageView1.ImageBitmap = b

The crop aspect ratio is a tall almost 20x1 shape, but Surprisingly when I select a picture again, it goes to the (a X a) block shape and locks it. It would seem like something initialises after the image was loaded. I have tried applying the crop at different stages that the CropImageView loads, but the only thing that works seems to be a second image selection. I'll let you know if I find a solution.
 

DavideV

Active Member
Licensed User
Longtime User
I


I do the following after choosing an image from library:

B4X:
        Dim b As Bitmap
        b.Initialize("",file_loc)
        CropImageView1.setAspectRatio(5,5)
        CropImageView1.FixedAspectRatio = True
        CropImageView1.ImageBitmap = b

The crop aspect ratio is a tall almost 20x1 shape, but Surprisingly when I select a picture again, it goes to the (a X a) block shape and locks it. It would seem like something initialises after the image was loaded. I have tried applying the crop at different stages that the CropImageView loads, but the only thing that works seems to be a second image selection. I'll let you know if I find a solution.


Nice, good to know :)
 

schalkgreyling

Member
Licensed User
Longtime User
Nice, good to know :)
Interesting Solution:
B4X:
Activity.LoadLayout("image_upload")
Dim c As Bitmap
c.Initialize(File.DirAssets,"images.png")
CropImageView1.ImageBitmap = c
CropImageView1.setAspectRatio(5,5)
CropImageView1.FixedAspectRatio = True
CropImageView1.Visible = False


Sub chooser_Result(Success As Boolean, Dir As String, FileName As String)
    If Success Then
Dim file_loc As String
file_loc = GetPathFromContentResult(FileName)
Dim b As Bitmap
b.Initialize("",file_loc)
CropImageView1.setAspectRatio(5,5)
CropImageView1.FixedAspectRatio = True
CropImageView1.ImageBitmap = b

I load a blank image into the CropImageView1 as the layout is loaded and set the visibility to false. Then when I select an image from the gallery and set visibility to true, the crop works perfectly. :)
 

Luiz Fernando Orlandini

Active Member
Licensed User
Longtime User
Hi there!

After I started using this library with B4A 6.0 my APP starts to crash.

Attached the exception.

Any thoughts?

Thanks.
 

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: 148

DonManfred

Expert
Licensed User
Longtime User
Any thoughts?
- we dont see any code
- Based on error yor ar missing a ressource. Forget to add #additionalres?
- Sou should post the error from the logwindow instead of a screenshot. Rightclick copy all
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
After I started using this library with B4A 6.0 my APP starts to crash.
I tried the sample with b4a 6 and it works fine here!

I checked the Resourcesfolder. It is available here. It is present in the ExampleZIP too.

If you add the lib to your project then you need to add the #additionalres directive for this lib too to match the folder where the resources are placed.

Make sure you added
B4X:
#AdditionalRes: ..\resources
pointing to the correct path of the resourcefolde of this lib.
 
Last edited:

JohnC

Expert
Licensed User
Longtime User
Curious,

Why when I load in some images, there is a dark tinted sub area that is smaller then the image size, but the crop window will only move around in this dark tinted area and I cant get the crop square to move to places on the image outside of the dark tinted area.

Anybody know why?
 

artsoft

Active Member
Licensed User
Longtime User
Hi all!

The same issue as other developers here:
I have to crop an image with fix square ratio. The width and the height have to be equal. So I try all solutions but no success until today.

See the screenshot below!

This is my code:

B4X:
Dim b2 as Bitmap
b2 = LoadBitmap(pwdinput.ez_path, pwdinput.ez_file)
crop.Visible = False
crop.ImageBitmap = b2
crop.rotateImage(90)
crop.setAspectRatio(5, 5)
crop.FixedAspectRatio = True
crop.Visible = True

And there is currently no way to crop square sections from the loaded image.

So, what could be the problem here?

Thx in advance to all helpers.

Regards
ARTsoft
 

Attachments

  • cropTest.png
    cropTest.png
    98.8 KB · Views: 160

MaFu

Well-Known Member
Licensed User
Longtime User
Responsive to some questions and problems in this thread:
The ImageCropper of my MFLib 2 ...
... can get and set crop position/dimension programmatically
... has no border area, the crop rectangle can moved/sized to the outmost bounds
... has working aspect ratio
 

scsjc

Well-Known Member
Licensed User
Longtime User
Hello Don Manfred,
i dont know where are my mistake.... some images can't select all image only center....

Screenshot_2016-10-25-09-32-30.png
 

scsjc

Well-Known Member
Licensed User
Longtime User
What is the question? I did not understand

I dont know why cant select all image only the center.... in this image can see the Zone-Select is only in the midle and can't move to select left corner, right corner ...
 
Top