Android Question cropping camera image to a sepesified rectangle

Discussion in 'Android Questions' started by Devv, Jun 22, 2015.

  1. Devv

    Devv Active Member Licensed User

    I'm trying to make an app that open the camera and shade all the screen except a rectangle
    the user must place that rectangle on something then press take picture button


    [​IMG]



    i want to crop the image only to the not grayed area

    this is what i tried

    Code:
    Sub Activity_Create(FirstTime As Boolean)
        
    Activity.LoadLayout("main")
        Cam1.Initialize(pnlCamera, 
    "Cam1")
      
    End Sub

    Sub Activity_Resume
      
        
    Activity.AddMenuItem("flash","mnuFlashOn")
        
    Activity.AddMenuItem("crop","crop")
      
    End Sub

    Sub Activity_Pause (UserClosed As Boolean)
        Cam1.StopPreview
        Cam1.Release
    End Sub

    Sub mnuFlashOn_Click
        Cam1.FlashOn()
    End Sub



    Sub Cam1_Ready (Success As Boolean)
        
    'camera is ready
        If Success Then
            Cam1.Oriportrait
            Cam1.PictureSize(
    480,320)
            Cam1.StartPreview  
        
    Else
            
    ToastMessageShow("Cannot open camera."True)
        
    End If
    End Sub

    Sub Cam1_PictureTaken2 (Data() As Byte)


        
    Dim dt As String
      
        
    Try
            
    File.MakeDir(File.DirRootExternal, "pics/")
        
    Catch
      
        
    End Try
      
        
    DateTime.DateFormat = "yyyyMMddHHmmssSSS" ' See this page regarding uppercase letters.
      
        dt = 
    DateTime.Date(DateTime.Now)
      
        
    Dim Out As OutputStream

    Try

    ToastMessageShow("Saving huge file now",True)

    Activity.Invalidate
        
    DoEvents()
      
        Out = 
    File.OpenOutput(File.DirRootExternal & "/pics/""out.jpg"False)
      
        Out.WriteBytes(Data, 
    0, Data.Length)
      
        Out.Flush
      
        Out.Close                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
      
      
    Catch
        
    Msgbox("Bombs out copying photo to DirRootExternal","Error")
    End Try
          Cam1.StartPreview
         Button1.Visible = 
    True
         Button1.Invalidate
         
    Activity.Invalidate
        
    DoEvents()
    End Sub

    Sub mnuTakePicture_Click

      
        button1_click
    End Sub

    Sub mnuFocusMode_Click
      
        
    'Cam1.setFocusMode = "MACRO"
      
    End Sub


    Sub button1_click
         Button1.Visible = 
    False
         Button1.Invalidate
      
        
    Activity.Invalidate
        
    DoEvents()
      
    'Cam1.Quality = 50
    'Cam1.Quality = 70
    Cam1.FocusMode = "MACRO"
    Cam1.Quality = 
    100
    Cam1.TakePicture2(
    90)
    End Sub


    how could i crop the token image so it marches the rectangle on all devices regardless of screen size or camera resolution of the device !?

    btw the rectangle is an image view

    ImageView1.Top = 0
    ImageView1.Left = 0
    ImageView1.Width = 100%x
    ImageView1.Height = 80%y


    here is the rectangle png


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