I need help with my issue of saving a picture . I am using adobe photo sdk to edit my image. Documentation link(https://creativesdk.adobe.com/docs/android/#/articles/imageediting/index.html). They say use .withOutput(Uri) to save the image which i created but get my image with an error.
public class MainActivity extends AppCompatActivity {
private static final int IMG_CODE_EDIT = 263;
private Button mPickbtn;
private Button mCapturebtn;
private static int RESULT_LOAD_IMAGE = 1;
private static final int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 100;
private String mCurrentPhotoPath;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mPickbtn = (Button) findViewById(R.id.pick_image);
mCapturebtn = (Button) findViewById(R.id.button2);
Intent cdsIntent = AdobeImageIntent.createCdsInitIntent(getBaseContext(), "CDS");
startService(cdsIntent);
}
public void takePicture(View view) {
// create Intent to take a picture and return control to the calling application
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// start the image capture Intent
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
}
public void onClick(View view) {
Intent i = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, RESULT_LOAD_IMAGE);
}
@Override
protected void onResume() {
super.onResume();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
//Gets the gallery image uri
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
Uri selectedImage = data.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
editPic(selectedImage);
}
//picture from camera
if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
Uri mPicTaken = data.getData();
editPic(mPicTaken);
} else if (resultCode == RESULT_CANCELED) {
// User cancelled the image capture
} else {
// Image capture failed, advise user
}
}
if (resultCode == RESULT_OK) {
switch (requestCode) {
/* 4) Make a case for the request code we passed to startActivityForResult() */
case 263:
/* 5) Show the image! */
Uri editedImageUri = data.getData();
Intent intent = new Intent("com.ayyogames.photoapp.Share");
intent.putExtra("imageUri", editedImageUri);
startActivity(intent);
break;
}
}
}
public void editPic(Uri uri) {
// Create the File where the photo should go
File photoFile = null;
try {
photoFile = createImageFile();
} catch (IOException ex) {
// Error occurred while creating the File
}
if (photoFile != null) {
Uri photoURI = FileProvider.getUriForFile(this,
"com.ayyogames.photoapp.fileprovider",
photoFile);
Intent intent = new AdobeImageIntent.Builder(this)
.setData(uri)
.withOutputSize(MegaPixels.Mp10)
.withOutputQuality(100)
.withOutput(photoURI)
.build();
startActivityForResult(intent, IMG_CODE_EDIT);
}
}
private File createImageFile() throws IOException {
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(
imageFileName, /* prefix */
".jpg", /* suffix */
storageDir /* directory */
);
// Save a file: path for use with ACTION_VIEW intents
mCurrentPhotoPath = "file:" + image.getAbsolutePath();
return image;
}
Share Class
public class Share extends AppCompatActivity {
private ImageView mEditedImageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_share);
Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
setSupportActionBar(myToolbar);
ActionBar ab = getSupportActionBar();
ab.setDisplayHomeAsUpEnabled(true);
mEditedImageView = (ImageView) findViewById(R.id.editedImageView);
Intent intent = getIntent();
Uri uri = intent.getParcelableExtra("imageUri");
mEditedImageView.setImageURI(uri);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_menu,menu);
return true;
}
}
The Image Editor developer guide currently says that you should pass a Uri
to withOutput()
, but this is incorrect.
Try passing a File
:
/* 1) Change the argument to your desired location */
File file = new File(Environment.getExternalStorageDirectory() + File.separator + "test.jpg");
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
Intent imageEditorIntent = new AdobeImageIntent.Builder(this)
.setData(imageUri)
.withOutput(file) /* 2) Pass the File here */
.build();
Your argument to the File
constructor should be altered to whatever location you desire.