0

This part is not working, how can I detect if the current camera positions is landscape or portrait? I know how to rotate a picture the problem is to detect if the height or weight is higher then change the image properties...

File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(
                    Environment.DIRECTORY_PICTURES), "MyCameraApp");                    


                    sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, 
                    Uri.parse("file://"+ mediaStorageDir)));

//What happen here?

private PictureCallback mPicture = new PictureCallback()
{
    @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
    @Override
    public void onPictureTaken(byte[] data, Camera camera){

        File pictureFile = getOutputMediaFile(MEDIA_TYPE_IMAGE);    

        try
        {
            FileOutputStream fos = new FileOutputStream(pictureFile);

            //if(mCamera.getSceneMode() == SCENE_MODE_PORTRAIT)
            //{
                //Bitmap bmp = BitmapFactory.decodeByteArray(data, 0, data.length);
                //bmp = rotateImage(90, bmp);
                //ByteArrayOutputStream stream = new ByteArrayOutputStream();
                //bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
                //data = stream.toByteArray();
            //}

            fos.write(data);
            fos.close();    

            File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(
                    Environment.DIRECTORY_PICTURES), "MyCameraApp");




                    sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, 
                    Uri.parse("file://"+ mediaStorageDir)));
        }

        catch(FileNotFoundException e)
        {
            Log.d(TAG, "File not found: "+e.getMessage());
        }
        catch(IOException e)
        {
            Log.d(TAG, "Error accessing file: "+e.getMessage());
        }
    }
};

public Bitmap rotateImage(int angle, Bitmap bitmapSrc) 
{
    Matrix matrix = new Matrix();
    matrix.postRotate(angle);
    return Bitmap.createBitmap(bitmapSrc, 0, 0, 
    bitmapSrc.getWidth(), bitmapSrc.getHeight(), matrix, true);
}

public static boolean isSdPresent() {   
    return android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);
}

private static File getOutputMediaFile(int type){
    File mediaFile = null; 
    if(isSdPresent() == false)
    {
        Log.d(TAG, "There is no Sd card. Cannot use the camera");
    }

   else
    {
        File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),".");

        if(!mediaStorageDir.exists())
        {
            if(!mediaStorageDir.mkdirs())
            {
                Log.d("WorldCupApp", "failed to create directory");
                return null;
            }
        }

         String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());       
         if (type == MEDIA_TYPE_IMAGE)
         {        
             mediaFile = new File(mediaStorageDir.getPath() + "IMG_"+ timeStamp + ".jpg");    
         } 
         else 
         {       
             return null;  
         }          
    }
    return mediaFile;
}       

}

pb77
  • 47
  • 9
  • Can you verify that your rotation is in fact being applied correctly by saving both the before and after rotation bitmaps? – TheIT Jan 14 '14 at 03:09
  • I think the problem was this thing that you mentioned... updated the code, can you check again? – pb77 Jan 14 '14 at 05:33
  • Your previous code was checking the EXIF data on the image. That was the correct approach. You shouldn't check the device's orientation as it may not be the same as when the photo was taken and may not be reliable in general. – TheIT Jan 14 '14 at 05:46
  • Okay changing again as it was, so what is the important part that I need to check if the file weight or height is bigger and then rotate? – pb77 Jan 14 '14 at 06:04
  • Sorry I can't provide you with more help right now, take a look at this Answer it might help (good luck!): http://stackoverflow.com/questions/8346955/android-camera-resulted-image-should-be-rotated-after-the-capture?rq=1 – TheIT Jan 14 '14 at 06:09

0 Answers0