B4A Library CameraFilter - 12 Aug: update in post #26

A shortcut wrap for this Github project. It applies a variety of filters to the live preview of the camera. I have asked the author of the Github project to add the necessary code so that pictures can be taken. He has agreed to do so and I will post an updated project once that is done.

You need the following Jars in your additional library folder (recent versions):
android-support-v7-appcompat.jar
android-support-v4.jar

Take note of the following code in the B4A project and set you path to suite your own computer:
B4X:
'IMPORTANT!!!! YOU NEED TO SET THE FOLLOWING PATHS CORRECTLY FOR YOUR OWN COMPUTER!!!!!!!!!!!!!!!!!!
'THE BELOW PATH IS THE PATH FOR MY COMPUTER
#AdditionalRes: C:\ANDRIOD_SDK_TOOLS\extras\android\support\v7\appcompat\res, android.support.v7.appcompat

Posting the following:
1. B4A library files - copy them to your additional library folder
2. B4A sample project

Sample code:
B4X:
#Region  Project Attributes
    #ApplicationLabel: CameraFilter
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#AdditionalRes: ..\resource
#AdditionalRes: ..\CameraFilter_res

'IMPORTANT!!!! YOU NEED TO SET THE FOLLOWING PATHS CORRECTLY FOR YOUR OWN COMPUTER!!!!!!!!!!!!!!!!!!
'THE BELOW PATH IS THE PATH FOR MY COMPUTER
#AdditionalRes: C:\ANDRIOD_SDK_TOOLS\extras\android\support\v7\appcompat\res, android.support.v7.appcompat

#Extends: android.support.v7.app.AppCompatActivity

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
 
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private Button1 As Button
    Private Label1 As Label
    Dim camerafilter As CameraFilter
 
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
 
    Activity.LoadLayout("main")
    camerafilter.Initialize("camerafilter")
    Label1.Visible = True
    Label1.Text = "Wrapped by Johan Schoeman"

End Sub

Sub Activity_Resume
 
 
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Button1_Click
 
  camerafilter.StartCameraFilter

End Sub

Pics of some of the available preview filters:

10.png


1.png



2.png


3.png



4.png


5.png


6.png


7.png
 

Attachments

  • b4aCameraFilter.zip
    256 KB · Views: 275
  • CameraFilterLibFiles.zip
    26.2 KB · Views: 269
Last edited:

Johan Schoeman

Expert
Licensed User
Longtime User
Attached new library files and B4A project that will allow you to take photos with the back facing camera (I need to sort out the front facing camera as it is upside down). See the camera icon at the top right. Photos taken will be stored/saved in the root folder of your device.


1.png
 

Attachments

  • CameraFilterLibFilesNew.zip
    26.9 KB · Views: 181
  • b4aCameraFilterNew.zip
    256 KB · Views: 161

susu

Well-Known Member
Licensed User
Longtime User
I didn't try your lib yet but it looks really cool. Can I move the camera button and change the folder to save picture?
Thank you Johan.
 

susu

Well-Known Member
Licensed User
Longtime User
I tested new lib but when I click on "Start CameraFilter" button there's error:

java.lang.NoSuchFieldError: No static field Theme of type [I in class Landroid/support/v7/appcompat/R$styleable; or its superclasses (declaration of 'android.support.v7.appcompat.R$styleable' appears in /data/app/JHS.CameraFilter-1/base.apk)
at android.support.v7.app.AppCompatDelegateImplV7.createSubDecor(AppCompatDelegateImplV7.java:305)
at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:278)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:252)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
at cn.nekocode.camerafilter.MainActivity.onCreate(MainActivity.java:50)
at android.app.Activity.performCreate(Activity.java:6057)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2330)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2439)
at android.app.ActivityThread.access$800(ActivityThread.java:162)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1348)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5421)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:914)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:707)

I didn't use AppCombat lib and changed Additional Res path correctly.
 

Johan Schoeman

Expert
Licensed User
Longtime User
I tested new lib but when I click on "Start CameraFilter" button there's error:



I didn't use AppCombat lib and changed Additional Res path correctly.
Try to clean the B4A project and see if it solves it.
 

Johan Schoeman

Expert
Licensed User
Longtime User
I tested new lib but when I click on "Start CameraFilter" button there's error:



I didn't use AppCombat lib and changed Additional Res path correctly.
I have updated the lib to the most recent code of the Github project (about 7 hours ago) but have added the ability to specify the folder and file name of the photos (note that the file name will automatically be appended with the name of the filter and a date + time stamp). My completed B4A folder has been zipped and you can download it from HERE. Use the attached library files with this B4A project.

Sample code:
B4X:
#Region  Project Attributes
    #ApplicationLabel: CameraFilter
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#AdditionalRes: ..\resource
#AdditionalRes: ..\CameraFilter_res

'IMPORTANT!!!! YOU NEED TO SET THE FOLLOWING PATHS CORRECTLY FOR YOUR OWN COMPUTER!!!!!!!!!!!!!!!!!!
'THE BELOW PATH IS THE PATH FOR MY COMPUTER
#AdditionalRes: C:\ANDRIOD_SDK_TOOLS\extras\android\support\v7\appcompat\res, android.support.v7.appcompat

'#Extends: android.support.v7.app.AppCompatActivity

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
  
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private Button1 As Button
    Private Label1 As Label
    Dim camerafilter As CameraFilter
  
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
  
    Activity.LoadLayout("main")
    camerafilter.Initialize("camerafilter")
    Label1.Visible = True
    Label1.Text = "Wrapped by Johan Schoeman"
  
    camerafilter.FolderName = "CAMERAFILTER"
    camerafilter.PictureName = "filter"           'this will automatically be appended with the name of the filter, the date, and the time (store as a png file)

End Sub

Sub Activity_Resume
  
  
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Button1_Click
  
  camerafilter.StartCameraFilter

End Sub
 

Attachments

  • CameraFilterLibFiles120816.zip
    31 KB · Views: 171

susu

Well-Known Member
Licensed User
Longtime User
Hi Johan,

I downloaded new lib, new B4A project. I cleaned the project before compile. I can compile your sample code but when I click on "Start CameraFilter" button, there's the same error. :(
 

Johan Schoeman

Expert
Licensed User
Longtime User
Hi Johan,

I downloaded new lib, new B4A project. I cleaned the project before compile. I can compile your sample code but when I click on "Start CameraFilter" button, there's the same error. :(
The APK that was created with B4A should be somewhere in the B4A folder (my original project). Install it and see if it runs....
 

susu

Well-Known Member
Licensed User
Longtime User
Your apk worked! It's strange :confused:
 

susu

Well-Known Member
Licensed User
Longtime User
I got the same error with your previous lib. Could you please add some things like:
- Add camera filter by code with customized size.
- Add capture button anywhere by code.
- Size of pixel/effect can be changed.
- Save picture in Jpeg.

I know I ask too much. But I believe you can do it. I will donate to you as my thanks. :)
 
Top