B4A Library CropImageView V1.0

Discussion in 'Additional libraries, classes and official updates' started by DonManfred, Mar 26, 2015.

  1. DonManfred

    DonManfred Expert Licensed User

    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) :)
    [​IMG]
     

    Attached Files:

    Last edited: Mar 26, 2015
  2. NJDude

    NJDude Expert Licensed User

    Awesome!

    I'm attaching a slightly better example, which allows you to SAVE the cropped picture.
     

    Attached Files:

  3. DonManfred

    DonManfred Expert Licensed User

    But no like? :(
    You have forgotten to include the Resource-folder :)
    Thank you for this Example!

    :)
     
  4. NJDude

    NJDude Expert Licensed User

    Oops!, ok, I have added the missing directory and reposted the sample on my previous post.
     
  5. Douglas Farias

    Douglas Farias Expert Licensed User

    this works perfect, i go make u a donation when i launch my app thx
     
    DonManfred likes this.
  6. shashkiranr

    shashkiranr Active Member Licensed User

    Hi DonManfred,

    Thank you for the library. I have an image that is 1364 X 2048 size. I want to fix the crop window only to my device height and size. How do you do that?

    Regards,
    SK
     
    Phayao likes this.
  7. Luiz Fernando Orlandini

    Luiz Fernando Orlandini Active Member Licensed User

    Hello I'm trying to use CroppedImage method combined with StringUtils.EncodeBase64, but it's resulting in a not valid Base64 string.

    Do you have any idea what is happening?

    Thanks
     
  8. DonManfred

    DonManfred Expert Licensed User

    No. I dont remember having a base64 routine inside this lib.... So; without seeing your code it is hard to give advices.
     
  9. Luiz Fernando Orlandini

    Luiz Fernando Orlandini Active Member Licensed User

    You're right Manfred. I don't use any code from this library to encode the image into a Base64 format.

    I don't have the code right now, but I do something like this:

    Code:
    Dim su As StringUtils
    Dim str As String = su.EncodeBase64(img.CroppedImage)
    img is declared as CropImageView.

    The issue here is, when I persist my str and try to decode them into a ImageView I got an exception. Even trying to convert using an online Base64 parser, I got the same message, that the String is a invalid Base64 string.

    I'm trying to figure out if the problem is related with the way CroppedImage handle to create the new Bitmap. Make sense?
     
  10. DonManfred

    DonManfred Expert Licensed User

    It will not work the way you do
    Code:
    img.CroppedImage
    will return a BITMAP, not a byte array

    You first need to convert the bitmap into a byte array

    Code:
    Dim out As OutputStream
    out.InitializeToBytesArray(
    0)
    dim bmp as Bitmap = img.CroppedImage
    bmp.WriteToStream(out, 
    100"PNG")
    out.Close
    Dim data() As Byte = out.ToBytesArray
    and then

    Code:
    Dim su As StringUtils
    Dim str As String = su.EncodeBase64(data)
    something like that... Have not tested it
     
  11. Luiz Fernando Orlandini

    Luiz Fernando Orlandini Active Member Licensed User

    Cool! I'll test it in the next hours!!!

    By the way, are you planning to create this library for B4I?
     
  12. MaFu

    MaFu Well-Known Member Licensed User

    Or you can use the BitmatToString function of my MFLib which converts a bitmap to Base64.
     
    DonManfred likes this.
  13. Luiz Fernando Orlandini

    Luiz Fernando Orlandini Active Member Licensed User

    Hey Manfred,

    no luck at all.

    Here is my code:

    Code:
    Sub btnChoosePhoto_Click
        
    Dim Chooser As ContentChooser
        Chooser.Initialize(
    "chooser")
        Chooser.Show(
    "image/*""Selecione uma nova foto para o aluno")
    End Sub

    Sub chooser_Result (Success As Boolean, Dir As String, FileName As String)
        
    If Success Then
            imageToCrop.ImageBitmap = 
    LoadBitmap(Dir,FileName)
        
    Else
            
    ToastMessageShow("Nenhuma foto selecionada"True)
        
    End If
    End Sub
    Code:
    Dim u As Utils
        u.Initialize
        
    Dim bmp as Bitmap = imageToCrop.CroppedImage
        
    Dim photo as String= u.ImageToBase64(bmp)
    Code:
    Public Sub ImageToBase64(img As BitmapAs String
       
    Dim su As StringUtils
       
    Dim out As OutputStream
       out.InitializeToBytesArray(
    0)
       img.WriteToStream(out, 
    75"JPEG")
       out.Close
       
    Return su.EncodeBase64(out.ToBytesArray)
    End Sub
    When I paste the result of photo in a Base64 decoder like http://base64online.org/decode/#, I got the message It seems like image file is broken.

    I also observed that photo variable has some blank spaces into that. This looks to be an issue when I try to decode Base64 format.
     
    Last edited: Jul 28, 2015
  14. Luiz Fernando Orlandini

    Luiz Fernando Orlandini Active Member Licensed User

    I also tried you library with the same result I got before. Any ideas?

    Code:
    Dim mf As MF_Image
        photo = mf.BitmapToString(bmp, 
    75)
     
  15. Luiz Fernando Orlandini

    Luiz Fernando Orlandini Active Member Licensed User

    Folks I found my mistake. After encode the bitmap I need to submit the image to an REST API. I solved this issue doing a EncodeURL =D

    Works like a charm now
     
    DonManfred likes this.
  16. DonManfred

    DonManfred Expert Licensed User

    [​IMG]
    I´m using exact the code i wrote above....

    Code:
    Sub Button1_Click
        
    Dim bmp As Bitmap = civ.CroppedImage
        
    Dim out As OutputStream
        out.InitializeToBytesArray(
    0)
        bmp.WriteToStream(out, 
    100"PNG")
        out.Close
        
    Dim data() As Byte = out.ToBytesArray
        ImageView1.Bitmap = bmp
        
    Dim su As StringUtils
        
    Dim str As String = su.EncodeBase64(data)
        
    File.WriteString(File.DirRootExternal,"base64.uue",str)
        
    'Log(str)
    End Sub
     
  17. DonManfred

    DonManfred Expert Licensed User

    glad you got it working
     
  18. Gorazdspajzer

    Gorazdspajzer Member Licensed 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
     
  19. DonManfred

    DonManfred Expert Licensed User

    The underlying library does not have such feature. And i dont know what i need to change to makeit work, sorry.
     
  20. Dogbonesix

    Dogbonesix Active Member Licensed User

    Exactly what I needed Except: I can not reload another image without exiting the app and reloading - don't know why. I would like to browse several pictures and crop them in the same folder. Very difficult when I have start the app for every image to crop.
    Also, some images won't display but will still crop - memory?
     
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