Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I need to save the image to the gallery or to any folder. Could you please help? #29

Open
Vernica1 opened this issue Mar 9, 2018 · 3 comments

Comments

@Vernica1
Copy link

Vernica1 commented Mar 9, 2018

No description provided.

@androidnoob123
Copy link

You can move the file to a different place in onImageCapture callback. See example here: https://github.com/sagan/android-hidden-camera/blob/master/app/src/main/java/me/sagan/magic/MagicService.java

Tool.java has the code to move the file.

@JhoanesFreitas
Copy link

CameraConfig().getBuild(context).setImageFile(your file).....build()

@Thisishowwedoit-2Moons
Copy link

Do not forget to add WRITE_EXTERNAL_STORAGE and READ_EXTERNAL_STORAGE permsissions and to add the file autority provider to work aswell as expected by android

`@Override
public void onImageCapture(@nonnull File imageFile) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.RGB_565;
Bitmap bitmap = BitmapFactory.decodeFile(imageFile.getAbsolutePath(), options);

    saveImageToExternalStorage(bitmap);
}`

`private void saveImageToExternalStorage(Bitmap finalBitmap) {
String root = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).toString();
File myDir = new File(root + "/locker_intruders_images");
myDir.mkdirs();
Random generator = new Random();
int n = 10000;
n = generator.nextInt(n);
String fname = "locker_image_" + n + ".jpg";
File file = new File(myDir, fname);
if (file.exists())
file.delete();
try {
FileOutputStream out = new FileOutputStream(file);
finalBitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
out.flush();
out.close();
}
catch (Exception e) {
e.printStackTrace();
}

    MediaScannerConnection.scanFile(this, new String[]{file.toString()}, null,
            new MediaScannerConnection.OnScanCompletedListener() {
                public void onScanCompleted(String path, Uri uri) {

                }
            });

}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants