位图方向更改

时间:2012-08-23 20:11:13

标签: android android-camera

我制作了一个自定义相机应用程序,我在相机点击后在imageview中显示我的图像。但在这里,我遇到的问题是我捕获的图像始终设置为更改的方向。

即如果我将相机作为人像拍摄时捕获图片,则不会将图像设置为纵向,而是更改方向。

这是相机点击代码: -

@Override
        public void onPictureTaken(byte[] data, Camera camera) {

            //here we write the code for saving the picture onto the sdCard


            File pictureFileDir = getDir();

            //to check whether directory exists or not!!
            if (!pictureFileDir.exists() && !pictureFileDir.mkdirs()) {

                //Log.d(Constants.DEBUG_TAG, "Can't create directory to save image.");
                Toast.makeText(Irant_Custom_cameraApplication.this, "Can't create directory to save image.",
                        Toast.LENGTH_LONG).show();
                return;

            }

            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyymmddhhmmss");
            String date = dateFormat.format(new Date());
            photo_file="Picture_"+date+".jpg";

            photo_FileName = pictureFileDir.getPath()+File.separator+photo_file;

            picture_file = new File(photo_FileName);

            FileOutputStream outStream = null;
            try{
                Toast.makeText(getApplicationContext(), "Image captured!", Toast.LENGTH_LONG).show();
                outStream = new FileOutputStream(picture_file);
                outStream.write(data);
                outStream.close();

                String imgpath = photo_file;
                System.out.println("Path for the image*********************"+photo_file);
                SignupDetails.imagePath=imgpath;

            }


            catch (Exception e) {

                Log.d("Image save error :", e.getMessage());    
            }
        }
    };

1 个答案:

答案 0 :(得分:0)

每个设备的实现并不总是相同,有些会自动旋转,有些则不会。我认为最好的方法是查看文件的EXIF数据。那是你最好的选择。