Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6253603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T14:01:49+00:00 2026-05-24T14:01:49+00:00

I am getting problem in saving a cropped image taken from camera at specified

  • 0

I am getting problem in saving a cropped image taken from camera at specified path in SD card.

code–>

public class PhotocropActivity extends Activity 
{
    /** Called when the activity is first created. */
    private static final int SELECT_PICTURE = 1;
    private static final int PICK_FROM_CAMERA = 2;
    private Uri muri;

    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        final CharSequence[] items = {"Capture New Image", "Upload from gallery"};
        AlertDialog.Builder builder  = new AlertDialog.Builder(PhotocropActivity.this);
        builder.setTitle("Select Image");
        builder.setItems(items, new DialogInterface.OnClickListener()
        {
            public void onClick(DialogInterface dialog, int item)
            {
                Intent intent = new Intent();
                intent.putExtra("crop", "true");
                intent.putExtra("aspectX", 730);
                intent.putExtra("aspectY", 1115);
                intent.putExtra("outputX", 730);
                intent.putExtra("outputY", 1115);
                intent.putExtra(MediaStore.EXTRA_OUTPUT, getTempFile());
                intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
                if(item==0)
               {
                    intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
                    startActivityForResult(intent, PICK_FROM_CAMERA);
               }
               else if(item==1)
               {
                    intent.setAction(Intent.ACTION_PICK);
                    intent.setType("image/*");
                    startActivityForResult(intent, SELECT_PICTURE);
                }
            }
            private Uri getTempFile()
            {
                 muri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(),"Image_" + String.Valueof(System.currentTimeMillis()) + ".jpg"));
                 return muri;
             } 
        });
        final AlertDialog alert = builder.create();
        ((Button) findViewById(R.id.button)).setOnClickListener(new OnClickListener() 
        {
            @Override
            public void onClick(View view)
            {
                alert.show();   
            }
        });
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) 
    {
        super.onActivityResult(requestCode, resultCode, data);

        switch(requestCode)
        {
            case PICK_FROM_CAMERA : if (resultCode == RESULT_OK)
            { 
                String filePath= muri.getPath();
                Toast.makeText(this, filePath, Toast.LENGTH_SHORT).show();
                Bitmap selectedImage = BitmapFactory.decodeFile(filePath);
                ImageView image = (ImageView)findViewById(R.id.selectedimage);
                image.setImageBitmap(selectedImage);
            }
            break;
            case SELECT_PICTURE : if (resultCode == RESULT_OK) 
            {
                  String filePath= muri.getPath();
                  Toast.makeText(this, filePath, Toast.LENGTH_SHORT).show();
                  Bitmap selectedImage =  BitmapFactory.decodeFile(filePath);
                  ImageView image = (ImageView)findViewById(R.id.selectedimage);
                  image.setImageBitmap(selectedImage);
            }
            break;
            default:
                break;
        }
    }
}

here when I debug it then it is showing NULLPOINTEREXCEPTION at String filePath= muri.getPath(); in PICK_FROM_CAMERA. but it’s showing muri value above in getTempFile().
Anyone help me.Fix the error in code?I m in great trouble.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T14:01:50+00:00Added an answer on May 24, 2026 at 2:01 pm

    hey I have solved this problem. and its perfect.here is the code–>

    case PICK_FROM_CAMERA : if (resultCode == RESULT_OK)
                { 
                    ContentValues values = new ContentValues();
                    values.put(Images.Media.TITLE, "title");
                    values.put(Images.Media.BUCKET_ID, "test");
                    values.put(Images.Media.DESCRIPTION, "test Image taken");
                    values.put(Images.Media.MIME_TYPE, "image/jpeg");
                    Uri uri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values);
                    Bitmap photo = (Bitmap) data.getExtras().get("data");
                    ((ImageView)findViewById(R.id.selectedimage)).setImageBitmap(photo);
                    OutputStream outstream;
                    try {
                            outstream = getContentResolver().openOutputStream(uri);
                            photo.compress(Bitmap.CompressFormat.JPEG,100, outstream);
                            outstream.close();
                    } catch (FileNotFoundException e) {}
                    catch (IOException e){}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having a problem getting a TreeView control to display node images. The code below
I am having a problem getting a list of fields from a query defined
I have a problem regarding getting the path of a user control. The scenario
Here's the problem: In C# I'm getting information from a legacy ACCESS database. .NET
We have a weird intermittent problem with saving from Word 2007 to our SharePoint
I'm getting some data from the web service and saving it in the core
I have already selected an image from SD card in my activity's ImageView using
I am facing a problem while saving a .csv file from browser. I made
I'm getting this problem: PHP Warning: mail() [function.mail]: SMTP server response: 550 5.7.1 Unable
I'm having a problem getting access to a database which lives on a remote

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.