Featured post

Marshmallow Features Point by Point

Android Runtime (“ART”) Improved application performance and lower memory overhead for faster  multi-tasking. Battery Doze...

Wednesday 28 January 2015

Take Image from Camera / Capture Image

// Take image from Android Device camera and get Back in onActivityResult

private void setTakePhotoCamera() 
{
long date_time=new Date().getTime();

File root = new File(Environment.getExternalStorageDirectory() 
                 + File.separator 
                 + "Folder_Name"
                 + File.separator);

root.mkdirs();
               
  File outputFile = new File(root, "sun"+date_time+".jpg");
  Uri outputFileUri_camera = Uri.fromFile(outputFile);

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT,outputFileUri_camera);
startActivityForResult(intent, CAMERA_PIC_REQUEST);
}


@Override
public void onActivityResult(int requestCode, int resultCode, final Intent data)
{

if (resultCode != RESULT_CANCELED)
{
                FileInputStream fileInputStreamVideo ;
              switch (requestCode)
               {
                    case CAMERA_PIC_REQUEST:
                    if (resultCode == RESULT_OK && data != null)
                   {  
                            try
                                  {
                                  String filePath = getPath(this, outputFileUri_camera);
                                      Bitmap bitmapPhoto = BitmapFactory.decodeFile(filePath, options);
                                      if (bitmapPhoto != null)
                                  {
                                              //int rotate = getCameraPhotoOrientation(this, filePath);
//bitmapPhoto = rotateBitmap(bitmapPhoto, rotate);
                                   
                             }
                          catch (Exception e)
                          {
                              System.out.println(" Exception.");
                              e.printStackTrace();
                          }
                }
             }
   }
  super.onActivityResult(requestCode, resultCode, data);
}

No comments:

Post a Comment