Android : Picture manipulation after capture

on Sunday, April 19, 2015


I need your help, if you are kind enough, into an issue that I'm having with my Android app:


I've managed to capture a picture in my MainActivity and display it into an separate activity - PictureActivity. My code is as follows:


In my MainActivity i have



private static final int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 100;

/**
* This is called in tap on a graphic element in my MainActivity layout
*/
public void launchCamera(View v) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
Bitmap imageData = null;

if (resultCode == RESULT_OK) {
imageData = (Bitmap) data.getExtras().get("data");

Intent i = new Intent(this, PictureActivity.class);
i.putExtra("captured_picture", imageData);
startActivity(i);
} else if (resultCode == RESULT_CANCELED) {
// User cancelled the image capture
} else {
Toast.makeText(getApplicationContext(), R.string.picture_capture_error, Toast.LENGTH_SHORT).show();
}
}
}


My PictureActivity looks like this:



public class PictureActivity extends ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_picture);

Bitmap bitmap = getIntent().getExtras().getParcelable("captured_picture");

ImageView view = (ImageView) findViewById(R.id.preview_photo);
view.setImageBitmap(bitmap);
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.image_menu, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();


return super.onOptionsItemSelected(item);
}
}


My PictureActivity layout looks like this



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
android:id="@+id/preview_photo"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>


This is how the final result looks so far:


PictureActivity screen preview


Long story short, these are the things I want to do next:



  • rotate the picture if the user taps on the middle button from the main action bar

  • crop the picture if the user taps on the first button from the left


Next, save the image somewhere (in shared preferences or session maybe?) and, aftewords, upload it to a remote server. I say "save the image somewhere" because the user can chose to take a second picture (from a maximum of two) and perform the same action, as above, on it (by taping on the first button from the right, in the main action bar).


What I can't figure out so far is:



  • how do I know what is the current image (that I see on my screen)

  • how can I set it's name and it's location where it should be saved to until I upload it to the remote server

  • how can I manipulate it when I tap on one of the two buttons (crop or rotate)


Sorry for the long post and thank you in advance for your help!


0 comments:

Post a Comment