Skip to content

Instantly share code, notes, and snippets.

@Arturo0021
Created August 10, 2018 23:02
Show Gist options
  • Select an option

  • Save Arturo0021/0813f749e9d10fe36e6773ff15300613 to your computer and use it in GitHub Desktop.

Select an option

Save Arturo0021/0813f749e9d10fe36e6773ff15300613 to your computer and use it in GitHub Desktop.
permissions
ActivityCompat.requestPermissions(Loader_Activity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
Implementation
private File mFile;
// Esto creara una imagen en una carpeta llamada App+nombre de tu aplicacion
File saveDir = new File(Environment.getExternalStorageDirectory(), "App" + getString(R.string.app_name));
saveDir.mkdirs();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyymmddhhmmss");
String date = dateFormat.format(new Date());
String fileName = "Picture_" + date + "_.jpg";
mFile = new File(saveDir, fileName);
// Donde Recuperas el take photo
ByteBuffer buffer = mImage.getPlanes()[0].getBuffer();
byte[] bytes = new byte[buffer.remaining()];
buffer.get(bytes);
FileOutputStream output = new FileOutputStream(mFile);
output.write(bytes);
FileInputStream FileIStr = new FileInputStream(mFile);
Bitmap bm = BitmapFactory.decodeStream(FileIStr);
int countByArray = bm.getRowBytes();
ByteArrayOutputStream out = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG, 70, out);
byte[] img = out.toByteArray();
encodeImgView = Base64.encodeToString(img, Base64.NO_WRAP);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment