Giter VIP home page Giter VIP logo

background-hidden-camera's Introduction

Background-Hidden-Camera

What is this Project for?

This Code allows application to take the picture using the device camera without showing the preview of it. Any application can capture the image from front or rear camera using Foreground service. You can capture images by running a Foreground service using this Code.

How it work?

Step-1: When you Open the application, this need few permission's - Camera Permission Application use this permission to open camera on dummy surface view to capture the picture. - App Overlay Permission Application use this permission to open a dummy surface view upon all apps. - Storage Read and Write Permission When picture captured then they save in your internal storage (name :: test.jpg), when you open app again this picture appears on activity_main.xml "ImageView"

Step-2: On button Clik a foreground Service start, Now Close the Application When Picture captured this service stopped and a Toast message appear, after that open the application --> Work Done

Function

Step-3: onPictureTaken()

  • In CameraView.java a function "onPictureTaken()", After Captured done, handle this event here

In this application code "onPictureTaken" Application convert

picture into bitmap

        BitmapFactory.Options opts = new BitmapFactory.Options();
        Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0,
                        data.length, opts);
        bitmap = Bitmap.createScaledBitmap(bitmap, 300, 300, false);

Then resize it using this code

        int height = bitmap.getHeight();
        int newWidth = 300;
        int newHeight = 300;

        // calculate the scale - in this case = 0.4f
        float scaleWidth = ((float) newWidth) / width;
        float scaleHeight = ((float) newHeight) / height;

        // createa matrix for the manipulation
        Matrix matrix = new Matrix();
        // resize the bit map
        matrix.postScale(scaleWidth, scaleHeight);

If you want to rotate the image

        matrix.postRotate(-90);

resize

        Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0,
                width, height, matrix, true);

        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        resizedBitmap.compress(Bitmap.CompressFormat.JPEG, 40,
                bytes);

Step-4: Store Picture (Internal Storage)

File f = new File(Environment.getExternalStorageDirectory()
                        + File.separator + "test.jpg");

                System.out.println("File F : " + f);

                f.createNewFile();
                // write the bytes in file
                FileOutputStream fo = new FileOutputStream(f);
                fo.write(bytes.toByteArray());
                // remember close de FileOutput
                fo.close();

That's it.

Demo

  • You can download or import this project on Android Studio to see how it's work.

Contribute:

Simple 3 step to contribute into this repo:

  1. Fork the project.
  2. Make required changes and commit.
  3. Generate pull request. Mention all the required description regarding changes you made.

Questions

Ping me on Linked_In Samran Tariq

Best Of Luck

background-hidden-camera's People

Contributors

samrantariq avatar

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.