iOS Question Crop image after select from camera roll

Discussion in 'iOS Questions' started by Luiz Fernando Orlandini, Feb 15, 2015.

  1. Luiz Fernando Orlandini

    Luiz Fernando Orlandini Active Member Licensed User

    Hi All.

    I need to select a photo from camera roll, and crop the image in a square format, and after show the cropped image in a ImageView
     
  2. omidaghakhani1368

    omidaghakhani1368 Well-Known Member Licensed User

    Hi.
    I attachment example of crop image view gallery and show it and roundimageview
     

    Attached Files:

  3. Luiz Fernando Orlandini

    Luiz Fernando Orlandini Active Member Licensed User

    This library is applied to Android, not for iOS. Am I rigth?
     
  4. Erel

    Erel Administrator Staff Member Licensed User

  5. Luiz Fernando Orlandini

    Luiz Fernando Orlandini Active Member Licensed User

  6. Erel

    Erel Administrator Staff Member Licensed User

    You will need to implement it.
     
  7. Luiz Fernando Orlandini

    Luiz Fernando Orlandini Active Member Licensed User

    Is it possible to set manual configurations of camera to take a square photo?
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    There is no square preset. However you can hide part of the preview panel and make it look like a square (and then crop the image based on the same dimensions).
     
  9. Luiz Fernando Orlandini

    Luiz Fernando Orlandini Active Member Licensed User

    I'm not sure if I understand...
     
  10. Erel

    Erel Administrator Staff Member Licensed User

    You can cover (with another panel) part of the preview panel to make it a square.
     
  11. Luiz Fernando Orlandini

    Luiz Fernando Orlandini Active Member Licensed User

    Just to update this. I found a alternative solution with ImageZoom library.
     
  12. pedrocam

    pedrocam Member Licensed User

    Hi B4Xrs

    After reading all of this plus more I made a working solution for myself. It is in no way beautiful or efficient, but it works, and that's what matters right now. I'm kind of new to B4i so realize that.

    The code below will crop, and resize an image. I use it to create a square profile picture from the rectangular images on the phone. It uses iMedia to access the pictures.

    I Use two ImageViews, one ScrollView, and a couple buttons.
    Hope it helps:


    Code:
    Sub CameraImageSelectButton_Click
        cam.Initialize(
    "cam", Page1)
        cam.SelectFromPhotoLibrary(
    Sender, cam.TYPE_ALL)
    End Sub

    Sub Cam_Complete (Success As Boolean, Image As Bitmap, VideoPath As String)
        
    If Success Then
            
    If Image.IsInitialized Then
        ImageView1.Bitmap = 
    Image
              
        ScrollView1.Panel.AddView(ImageView1,
    0,0,(ImageView1.Bitmap.Width * .3),(ImageView1.Bitmap.Height * .3)) 'im reducing the image size by 1/3 because it is huge
        ScrollView1.ContentHeight = ImageView1.Height
        ScrollView1.ContentWidth = ImageView1.Width
            
    Else
                
    Msgbox("Error retrieving image","Error")
            
    End If
        
    End If
    End Sub


    Sub BtnSave_Click
    Dim cnv As Canvas

    cnv.Initialize(ScrollView1)

    cnv.Refresh
    Dim rectDest As Rect
    rectDest.Initialize(
    00, ImageView2.Width, ImageView2.Height)

    cnv.DrawView(ScrollView1,rectDest)

    Dim bmp As Bitmap
    bmp = cnv.CreateBitmap

    cnv.Refresh
    Dim out As OutputStream = File.OpenOutput(File.DirDocuments, "ProfPic.jpg"False)
    bmp.WriteToStream(out, 
    100"JPEG")
    out.Close

    ImageView2.Bitmap = 
    LoadBitmap(File.DirDocuments, "ProfPic.jpg")

    End Sub

    Sub BtnEnlarge_Click
        ImageView1Test.Width = (ImageView1Test.Width * 
    1.5)
        ImageView1Test.Height = (ImageView1Test.Height * 
    1.5)
      
        ImgScroll.ContentHeight = ImageView1Test.Height
        ImgScroll.ContentWidth = ImageView1Test.Width
    End Sub

    Sub BtnSmaller_Click
            ImageView1Test.Width = (ImageView1Test.Width / 
    1.5)
        ImageView1Test.Height = (ImageView1Test.Height / 
    1.5)
      
        ImgScroll.ContentHeight = ImageView1Test.Height
        ImgScroll.ContentWidth = ImageView1Test.Width
    End Sub
     
    tamayo461 likes this.
  13. tamayo461

    tamayo461 Member Licensed User

    Thanks my frend...
     
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