Giter Club home page Giter Club logo

paracamera's Introduction

ParaCamera

Download Android Arsenal

Simple android camera to capture and get bitmaps in three simple steps:

1. Build Camera

// Create global camera reference in an activity or fragment
Camera camera;

// Build the camera   
camera = new Camera.Builder()
                .resetToCorrectOrientation(true)// it will rotate the camera bitmap to the correct orientation from meta data
                .setTakePhotoRequestCode(1)
                .setDirectory("pics")
                .setName("ali_" + System.currentTimeMillis())
                .setImageFormat(Camera.IMAGE_JPEG)
                .setCompression(75)
                .setImageHeight(1000)// it will try to achieve this height as close as possible maintaining the aspect ratio; 
                .build(this);

2. Capture Image

// Call the camera takePicture method to open the existing camera             
        try {
            camera.takePicture();
        }catch (Exception e){
            e.printStackTrace();
        }

3. Get bitmap and saved image path

// Get the bitmap and image path onActivityResult of an activity or fragment
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(requestCode == Camera.REQUEST_TAKE_PHOTO){
            Bitmap bitmap = camera.getCameraBitmap();
            if(bitmap != null) {
                picFrame.setImageBitmap(bitmap);
            }else{
                Toast.makeText(this.getApplicationContext(),"Picture not taken!",Toast.LENGTH_SHORT).show();
            }
        }
    }   
// The bitmap is saved in the app's folder
//  If the saved bitmap is not required use following code
    @Override
    protected void onDestroy() {
        super.onDestroy();
        camera.deleteImage();
    }

Gradle

implementation 'com.mindorks:paracamera:0.2.2'

WRITE_EXTERNAL_STORAGE is required

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

About The Author

You can connect with me here:

paracamera's People

Contributors

gogeta95 avatar janishar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

paracamera's Issues

getCameraBitmap() null

The following:-

@Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (requestCode == Camera.REQUEST_TAKE_PHOTO) {

            Bitmap bm = camera.getCameraBitmap(); // <-- Causes null exception

           }
    }

Results in the following error:-

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.graphics.Bitmap com.mindorks.paracamera.Camera.getCameraBitmap()' on a null object reference

Library: com.mindorks:paracamera:0.2.2
API: 23

Note: Image is displayed in gallery. getCameraBitmapPath() does return a valid file path

How to get the compressed Image

even doing this

camera = new Camera.Builder()
.resetToCorrectOrientation(true)// it will rotate the camera bitmap to the correct orientation from meta data
.setTakePhotoRequestCode(99)
//.setDirectory("pics")
//.setName("dir_" + System.currentTimeMillis())
.setImageFormat(Camera.IMAGE_JPEG)
.setCompression(75)
.setImageHeight(1000)// it will try to achieve this height as close as possible maintaining the aspect ratio;
.build(CaptureActivity.this);

got me the full size bitmap
camera.getCameraBitmap();

Create from Fragment

When I create from a fragment my onActivityResult is never called because to create I pass an activity like this ...

public class MyFragment extends Fragment {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    camera = new Camera(this.getActivity());

...

can't access front camera

this library is helpful for me, but I can't access the front camera, how to solve this problem?

Thanks a lot :)

Samsung galaxy tab Crash on click of OK

I am getting crash in samsung galaxy tab, Android 8.1.0:

2018-11-28 20:40:49.041 13731-13731/? E/libpersona: scanKnoxPersonas
2018-11-28 20:40:49.042 13731-13731/? E/libpersona: Couldn't open the File - /data/system/users/0/personalist.xml - No such file or directory

FileProvider Security Issues

API 16

App crashes due to File Provider security issue:-

02-25 16:49:46.281 1371-1371/? E/AndroidRuntime: FATAL EXCEPTION: main
                                                 java.lang.IllegalStateException: Could not execute method of the activity
                                                     at android.view.View$1.onClick(View.java:3591)
                                                     at android.view.View.performClick(View.java:4084)
                                                     at android.view.View$PerformClick.run(View.java:16966)
                                                     at android.os.Handler.handleCallback(Handler.java:615)
                                                     at android.os.Handler.dispatchMessage(Handler.java:92)
                                                     at android.os.Looper.loop(Looper.java:137)
                                                     at android.app.ActivityThread.main(ActivityThread.java:4745)
                                                     at java.lang.reflect.Method.invokeNative(Native Method)
                                                     at java.lang.reflect.Method.invoke(Method.java:511)
                                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
                                                     at dalvik.system.NativeStart.main(Native Method)
                                                  Caused by: java.lang.reflect.InvocationTargetException
                                                     at java.lang.reflect.Method.invokeNative(Native Method)
                                                     at java.lang.reflect.Method.invoke(Method.java:511)
                                                     at android.view.View$1.onClick(View.java:3586)
                                                     at android.view.View.performClick(View.java:4084) 
                                                     at android.view.View$PerformClick.run(View.java:16966) 
                                                     at android.os.Handler.handleCallback(Handler.java:615) 
                                                     at android.os.Handler.dispatchMessage(Handler.java:92) 
                                                     at android.os.Looper.loop(Looper.java:137) 
                                                     at android.app.ActivityThread.main(ActivityThread.java:4745) 
                                                     at java.lang.reflect.Method.invokeNative(Native Method) 
                                                     at java.lang.reflect.Method.invoke(Method.java:511) 
                                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 
                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
                                                     at dalvik.system.NativeStart.main(Native Method) 
                                                  Caused by: java.lang.SecurityException: Permission Denial: opening provider android.support.v4.content.FileProvider from ProcessRecord{537e1d30 1371:com.android.camera/u0a22} (pid=1371, uid=10022) that is not exported from uid 10048
                                                     at android.os.Parcel.readException(Parcel.java:1425)
                                                     at android.os.Parcel.readException(Parcel.java:1379)
                                                     at android.app.ActivityManagerProxy.getContentProvider(ActivityManagerNative.java:2354)
                                                     at android.app.ActivityThread.acquireProvider(ActivityThread.java:4219)
                                                     at android.app.ContextImpl$ApplicationContentResolver.acquireUnstableProvider(ContextImpl.java:1711)
                                                     at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1099)
                                                     at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:614)
                                                     at android.content.ContentResolver.openOutputStream(ContentResolver.java:487)
                                                     at android.content.ContentResolver.openOutputStream(ContentResolver.java:463)
                                                     at com.android.camera.Camera.doAttach(Camera.java:1385)
                                                     at com.android.camera.Camera.onReviewDoneClicked(Camera.java:1362)
                                                     at java.lang.reflect.Method.invokeNative(Native Method) 
                                                     at java.lang.reflect.Method.invoke(Method.java:511) 
                                                     at android.view.View$1.onClick(View.java:3586) 
                                                     at android.view.View.performClick(View.java:4084) 
                                                     at android.view.View$PerformClick.run(View.java:16966) 
                                                     at android.os.Handler.handleCallback(Handler.java:615) 
                                                     at android.os.Handler.dispatchMessage(Handler.java:92) 
                                                     at android.os.Looper.loop(Looper.java:137) 
                                                     at android.app.ActivityThread.main(ActivityThread.java:4745) 
                                                     at java.lang.reflect.Method.invokeNative(Native Method) 
                                                     at java.lang.reflect.Method.invoke(Method.java:511) 
                                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 
                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 
                                                     at dalvik.system.NativeStart.main(Native Method) 

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.