项目作者: SamranTariq

项目描述 :
This project take picture using front/rare camera without showing camera preview even the app is closed/kill.
高级语言: Java
项目地址: git://github.com/SamranTariq/Background-Hidden-Camera.git
创建时间: 2020-09-16T05:57:31Z
项目社区:https://github.com/SamranTariq/Background-Hidden-Camera

开源协议:

下载


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

  1. - Camera Permission
  2. Application use this permission to open camera on dummy surface view to capture the picture.
  3. - App Overlay Permission
  4. Application use this permission to open a dummy surface view upon all apps.
  5. - Storage Read and Write Permission
  6. 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

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

Then resize it using this code

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

  1. // calculate the scale - in this case = 0.4f
  2. float scaleWidth = ((float) newWidth) / width;
  3. float scaleHeight = ((float) newHeight) / height;
  4. // createa matrix for the manipulation
  5. Matrix matrix = new Matrix();
  6. // resize the bit map
  7. matrix.postScale(scaleWidth, scaleHeight);
  1. If you want to rotate the image
  1. matrix.postRotate(-90);
  1. resize
  1. Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0,
  2. width, height, matrix, true);
  3. ByteArrayOutputStream bytes = new ByteArrayOutputStream();
  4. resizedBitmap.compress(Bitmap.CompressFormat.JPEG, 40,
  5. bytes);
  1. Step-4: Store Picture (Internal Storage)

File f = new File(Environment.getExternalStorageDirectory()

  1. + File.separator + "test.jpg");
  2. System.out.println("File F : " + f);
  3. f.createNewFile();
  4. // write the bytes in file
  5. FileOutputStream fo = new FileOutputStream(f);
  6. fo.write(bytes.toByteArray());
  7. // remember close de FileOutput
  8. 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