0

I'm currently developing an Android Application. My current progress is that I successful develop custom android camera. I followed this step (http://courses.oreillyschool.com/android2/CameraAdvanced.html) The tutorial given saved the picture taken into the gallery, but I want to insert the name, description, and other information of the Image because I'm going to save the image along with the details that the user enter into my database.

Here for example on my interface:

a) Success taken Image:

enter image description here

b) The image that need to be pass to another Imageview (red circle):

enter image description here

I want the save button able to pass the image that had been taken to the ImageView(red circle) and not to store the image into the gallery. And here's are the code on the save button:

private View.OnClickListener mSaveImageButtonClickListener = new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        File saveFile = openFileForImage();
        if (saveFile != null) {
            saveImageToFile(saveFile);
        } else {
            Toast.makeText(Capturingimage.this, "Unable to open file to save the image.", Toast.LENGTH_LONG).show();
        }
    }
};

This is save image to file method:

private void saveImageToFile(File file) {
    if (mCameraBitmap != null) {
        FileOutputStream outStream = null;
        try {
            outStream = new FileOutputStream(file);
            if (!mCameraBitmap.compress(Bitmap.CompressFormat.PNG, 100, outStream)) {
                Toast.makeText(Capturingimage.this, "Unable to save image to file.",
                        Toast.LENGTH_LONG).show();
            } else {
                Toast.makeText(Capturingimage.this, "Saved image to: " + file.getPath(),
                        Toast.LENGTH_LONG).show();
            }
            outStream.close();
        } catch (Exception e) {
            Toast.makeText(Capturingimage.this, "Unable to save image to file.",
                    Toast.LENGTH_LONG).show();
        }
    }
}

My ImageView(redCircle) id is : @+id/image_view_after_capture

If you guys aren't very clear with the codes, here's the link on the full source code (http://courses.oreillyschool.com/android2/CameraAdvanced.html) on MainActivity.java. I'm sorry if my question is a lil bit messy and less explanation on the codes. I'm new to android programming, I hope you guys can teach me. I really appreciate your time and help to consider to help me.

Thank you in Advance!

bo2
  • 653
  • 1
  • 7
  • 12
  • As you are storing image in file then you can use this file and show it in 2nd activity, you can take help from [here](http://stackoverflow.com/questions/4181774/show-image-view-from-file-path-in-android) to read image from file show in imageview – Ichigo Kurosaki Dec 31 '15 at 10:11
  • To transfer image to other activity then you can have two way: 1. You save file to storage then paste image path to other activity by intent.putExtra(value); 2. You can temporary save image to static variable then you can access this static from any activity – GiapLee Dec 31 '15 at 10:11

1 Answers1

0

when you save image than hold your captured image path and pass to another activity where you want to show

 String mCaptureImagePath="";
     private void saveImageToFile(File file) {
        if (mCameraBitmap != null) {
            FileOutputStream outStream = null;
            try {
                outStream = new FileOutputStream(file);
                if (!mCameraBitmap.compress(Bitmap.CompressFormat.PNG, 100, outStream)) {
                    Toast.makeText(Capturingimage.this, "Unable to save image to file.",
                            Toast.LENGTH_LONG).show();
                } else {
 mCaptureImagePath=file.getPath();  //**** this is your save image path
                    Toast.makeText(Capturingimage.this, "Saved image to: " + file.getPath(),
                            Toast.LENGTH_LONG).show();
                }
                outStream.close();
            } catch (Exception e) {
                Toast.makeText(Capturingimage.this, "Unable to save image to file.",
                        Toast.LENGTH_LONG).show();
            }
        }
    }

After show image where you want like this

BitmapFactory.Options bmOptions = new BitmapFactory.Options();
Bitmap bitmap = BitmapFactory.decodeFile(mCaptureImagePath,bmOptions);
yourImageView.setImageBitmap(bitmap);
Mohit Suthar
  • 8,725
  • 10
  • 37
  • 67
  • Hi @Mohit :) Thank you for wiling to answer and help me :) But may I know on the BitmapFactory.Option bmOption = new BitmapFactory.Option (cont) will be put? under which code? I'm sorry for burden you, I'm not good at coding :/ – bo2 Dec 31 '15 at 13:44
  • @bo2 Sorry, i am not getting ! – Mohit Suthar Jan 01 '16 at 04:41
  • Hi mohit! Sorry for the lack of explanation there, I meant the the second code that you provide, where should I place it. – bo2 Jan 01 '16 at 04:42
  • In second image in your question you want to show, if you have another activity than you have to pass image path to that activity and showing image like above code, hope understand. – Mohit Suthar Jan 01 '16 at 04:52
  • If you need than check this link http://stackoverflow.com/questions/4181774/show-image-view-from-file-path-in-android – Mohit Suthar Jan 01 '16 at 04:57