Image Attachment Dialog is library that will allow you to select image from gallery or camera and compressed it and give it to you size will reduce.I designed it to get compressed files for retrofit
- Make dialog of this
- Capture image using Camera
- Select Image From Gallery
- Callbacks gives file and bitmaps
- Also Give Compressed Files and Bitmaps
The easiest way to get started using ImageAttachmentDialog is to add it as a gradle
dependency. You need to make sure you have the maven { url 'https://jitpack.io' } repositories
included in the build.gradle
file in the root of your project:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Next add a gradle compile dependency to the build.gradle
file of your app
module. The following will add a dependency to the full library:
dependencies {
implementation 'com.github.khizar1556:ImageAttachmentDialog:1.5'
}
private DialogImageAttachment dialogImageAttachment;
dialogImageAttachment = DialogImageAttachment.make(this).show();
dialogImageAttachment = DialogImageAttachment.make(this).setCallback(new ImageAttachentCallback() {
@Override
public void onSuccess(File originalFile, File compressedFile) {
}
@Override
public void onSuccess(Bitmap originalFileBitmap, Bitmap compressedFileBitmap) {
// if (originalFileBitmap != null) {
// originalIv.setImageBitmap(originalFileBitmap);
// }
// if (compressedFileBitmap != null) {
// compressedIv.setImageBitmap(compressedFileBitmap);
// }
}
@Override
public void onFailure(String error) {
Toast.makeText(MainActivity.this,error,Toast.LENGTH_SHORT).show();
}
@Override
public void onClick(Intent intent, int id) {
startActivityForResult(intent, id);
}
}).show();
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
dialogImageAttachment.onActivityResult(requestCode, resultCode, data);
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
dialogImageAttachment.onRequestPermissionsResult(requestCode, permissions, grantResults);
}