Closed cviacmob closed 5 years ago
public void choosePhotoFromGallary() { Intent galleryIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); startActivityForResult(galleryIntent, GALLERY); } private void takePhotoFromCamera() { Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(intent, CAMERA); } @override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == getActivity().RESULT_CANCELED) { return; } switch (clickImage) { case 1: if (requestCode == GALLERY) { if (data != null) { Uri contentURI = data.getData(); try { Bitmap bitmap = MediaStore.Images.Media.getBitmap(getActivity().getContentResolver(), contentURI); //String path = saveImage(bitmap); encodedImage = encodeImage(bitmap); mImageView.setImageBitmap(bitmap); Toast.makeText(getActivity(), "Image Saved!", Toast.LENGTH_SHORT).show();
} catch (IOException e) { e.printStackTrace(); Toast.makeText(getActivity(), "Failed!", Toast.LENGTH_SHORT).show(); } Glide.with(this).load(contentURI) .override(200, 200) .crossFade() .centerCrop() .into(mImageView); } } else if (requestCode == CAMERA) { Uri contentURI = data.getData(); Bitmap thumbnail = (Bitmap) data.getExtras().get("data"); mImageView.setImageBitmap(thumbnail); encodedImage = encodeImage(thumbnail); saveImage(thumbnail); Toast.makeText(getActivity(), "Image Saved!", Toast.LENGTH_SHORT).show(); }
} private String encodeImage(Bitmap bm) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bm = getResizedBitmap(bm, 450); bm.compress(Bitmap.CompressFormat.PNG, 100, baos); byte[] b = baos.toByteArray(); String encImage = Base64.encodeToString(b, Base64.DEFAULT); return encImage; }
attached the example for the your dexter images.
public void choosePhotoFromGallary() { Intent galleryIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); startActivityForResult(galleryIntent, GALLERY); } private void takePhotoFromCamera() { Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(intent, CAMERA); } @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == getActivity().RESULT_CANCELED) { return; } switch (clickImage) { case 1: if (requestCode == GALLERY) { if (data != null) { Uri contentURI = data.getData(); try { Bitmap bitmap = MediaStore.Images.Media.getBitmap(getActivity().getContentResolver(), contentURI); //String path = saveImage(bitmap); encodedImage = encodeImage(bitmap); mImageView.setImageBitmap(bitmap); Toast.makeText(getActivity(), "Image Saved!", Toast.LENGTH_SHORT).show();
} private String encodeImage(Bitmap bm) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); bm = getResizedBitmap(bm, 450); bm.compress(Bitmap.CompressFormat.PNG, 100, baos); byte[] b = baos.toByteArray(); String encImage = Base64.encodeToString(b, Base64.DEFAULT); return encImage; }
attached the example for the your dexter images.![image](https://user-images.githubusercontent.com/23516580/55454501-c44d5500-55fd-11e9-8f81-6903a476bc63.png)