Advanced Camera Library

XverhelstX

Well-Known Member
Licensed User
Longtime User
Heey,

I'm editing the camera library a bit and added some functions already like enabling the flash light and more.

but i'm stuck with the focus modes:

B4X:
    /**
     *Sets the focus mode to: Infinity.
     */
    public void FocusModeInfinity() {
       Parameters params = c.getParameters();
        params.setFocusMode( Parameters.FOCUS_MODE_INFINITY );
        c.setParameters(params);  
        
    }
    
    /**
     *Sets the focus mode to: Macro. 
     *Close-up
     */
    public void FocusModeMacro() {
       Parameters params = c.getParameters();
        params.setFocusMode( Parameters.FOCUS_MODE_MACRO );
        c.setParameters(params);  
     
    }

When I change this to FocusModeMacro or FocusModeInfinity, It just won't change and the pictures taken are still the same quality. (like no macro shot of text)

Any help?

XverhelstX
 

XverhelstX

Well-Known Member
Licensed User
Longtime User
@Erel: Thanks Erel,

I still have some problems though.

1) I still don't get the AutoFocus.

B4X:
private Camera.AutoFocusCallback mAutofocusCallback = new Camera.AutoFocusCallback()
    {
     @Override
     public void onAutoFocus(boolean success, Camera camera)
     {
        
     }
    };

    /**
     *Sets the focus mode to: Macro. 
     *Close-up
     */
    public void FocusModeMacro() {
       Parameters params = c.getParameters();
        params.setFocusMode( Parameters.FOCUS_MODE_MACRO );
        c.autoFocus( mAutofocusCallback );
        c.setParameters(params);  
     
    }

2) Camera1.PictureSize(100,100) gives me an error on B4Android. setParameters Failed.
B4X:
/**
     * Sets the size of the picture in pixels.
     */
    public void PictureSize(int width, int height) {
       Camera.Parameters params = c.getParameters();
       params.setPictureSize(width, height);
       c.setParameters(params);

    }

3) Frontcamera: should change the camera to my front camera?
Doesn't wor.

B4X:
    public void CameraFront(){
       Camera.Parameters params = c.getParameters();
       params.set("camera_id", 2);
       c.setParameters(params);
    
        
    }

4) And do I also need to add some other permission other than the Camera and Flashlight permission?


@NeoTechni: I'm still working on it. It hope it will be released later this day. I will also try to add the resolution thing.

XverhelstX
 
Last edited:
Upvote 0

agraham

Expert
Licensed User
Longtime User
Have you missed this in the documentation. Look at Camera.autoFocus and for Camera.Parameters.getFocusMode. You have to start it going for it to work.
Applications should call autoFocus(AutoFocusCallback) to start the focus if focus mode is FOCUS_MODE_AUTO or FOCUS_MODE_MACRO.
 
Upvote 0

XverhelstX

Well-Known Member
Licensed User
Longtime User
didn't I do this here:?

B4X:
private Camera.AutoFocusCallback mAutofocusCallback = new Camera.AutoFocusCallback()
    {
     @Override
     public void onAutoFocus(boolean success, Camera camera)
     {
        
     }
    };

    /**
     *Sets the focus mode to: Macro. 
     *Close-up
     */
    public void FocusModeMacro() {
       Parameters params = c.getParameters();
        params.setFocusMode( Parameters.FOCUS_MODE_MACRO );
        [B][U]c.autoFocus[/U][/B]( mAutofocusCallback );
        c.setParameters(params);  
     
    }

xverhelstx
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
But are you doing it at the correct time? I haven't seen the rest of your library code nor your B4A test code so I can't tell. Are you conforming to this requirement?
public final void autoFocus (Camera.AutoFocusCallback cb)
Since: API Level 1 Starts camera auto-focus and registers a callback function to run when the camera is focused. This method is only valid when preview is active (between startPreview() and before stopPreview()).
 
Upvote 0

NeoTechni

Well-Known Member
Licensed User
Longtime User
Could I have a copy? I have an hour before I have to leave on my vacation and Id love an app to take pictures using the R button (Xperia Play)
 
Upvote 0

NeoTechni

Well-Known Member
Licensed User
Longtime User
I'm not sure you will be able to take picture with the R button of the Xperia PLAY.

Sub Acitivity_Keypress(keycode as int)
if keycode = R_Trigger then
take_picture
end if
end sub

You can do it now with the existing library, but it's only 640*480/useless
 
Upvote 0

XverhelstX

Well-Known Member
Licensed User
Longtime User
nice didn't know this.

Is this also possible for the arrow (d-pad) and Square, Triangle, Cross and circle?

On topic: In attachements you can find the AC Library. (Advancec Camera Library)

Just to let you know that it is really unstable and some functions don't work.
 
Last edited:
Upvote 0

NeoTechni

Well-Known Member
Licensed User
Longtime User
nice didn't know this.

Is this also possible for the arrow (d-pad) and Square, Triangle, Cross and circle?

Yup, every button except:
-The touchpad doesnt work at all (Needs NDK stuff...)
-You need to return true for the O button so it doesnt quit the program
-This disables the back button from quitting as well
-The home button quits no matter what
 
Upvote 0

NeoTechni

Well-Known Member
Licensed User
Longtime User
'L 102 R 103 Back 4
'Up 19 Left 21 Right 22 Down 20
'T 100 S 99 O 4 X 23
'Start 108 Select 109 Menu 82 Search 84
 
Upvote 0

NeoTechni

Well-Known Member
Licensed User
Longtime User
How do I use it?

B4X:
Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
   Dim Cam As AdvancedCamera,Panel1 As Panel 
   Panel1.Initialize( "Panel1")
   
End Sub

Sub Activity_Create(FirstTime As Boolean)
   activity.AddView(panel1,0,0,100%x,100%y)
   cam.Initialize(Panel1, "Camera" )
        cam.PictureSize(2592 , 1944)
   cam.StartPreview
End Sub

Sub Activity_KeyPress (KeyCode As Int) As Boolean 'return true if you want to consume the event
   Select Case keycode
      Case 103
         cam.TakePicture 
   End Select
End Sub

It fails on start preview

Ah, it works like the other one, gotta use ready/picturetaken
 
Last edited:
Upvote 0

XverhelstX

Well-Known Member
Licensed User
Longtime User
B4X:
Sub Activity_Resume
   
   camera1.Initialize(panel1, "Camera1")
   
End Sub

Sub Activity_Pause (UserClosed As Boolean)
   camera1.Release
End Sub

Sub Camera1_Ready (Success As Boolean)
   If success Then
      Camera1.StartPreview
      
   Else
      ToastMessageShow("Cannot open camera.", True)
   End If
End Sub

Sub Camera1_PictureTaken (Data() As Byte)
   camera1.StartPreview

   Dim out As OutputStream
   out = File.OpenOutput(File.DirRootExternal, "test.jpg", False)
   out.WriteBytes(data, 0, data.Length)
   out.Close
   ToastMessageShow("Image saved: " & File.Combine(File.DirRootExternal, "Test.jpg"), True)
   
   
   
End Sub

Sub mnuTakePicture_Click
   
   camera1.CameraBack
   
End Sub

something like this?
it works on my PLAY

XverhelstX

EDIT: K, does PictureSize works?
 
Upvote 0
Top