2

我正在尝试Surfaceholder在 Android 中捕获图像,并希望同时支持横向和纵向照片。现在尝试了无数解决方案,其中一些适用于 HTC 设备,但不适用于三星设备。所以现在我要采用这种ExifInterface.TAG_ORIENTATION方法,因为我已经读过它也应该适用于三星设备。

PictureCallback myPictureCallback_JPG = new PictureCallback(){

                @Override
                public void onPictureTaken(byte[] byteArray, Camera arg1) {

                    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddhhmmss");
                    String date = dateFormat.format(new Date());

                    String _path = Environment.getExternalStorageDirectory() + File.separator + "xxx" + File.separator + "xxx" + date + ".jpeg";
                    File file = new File( _path );
                    Uri uriTarget = Uri.fromFile( file );               

                    try {
                        FileOutputStream fos = new FileOutputStream(file);

                        Bitmap realImage = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);

                        ExifInterface exif=new ExifInterface(file.getAbsolutePath());

                        Log.d("EXIF value", exif.getAttribute(ExifInterface.TAG_ORIENTATION));
                        if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("6")){
                            realImage= rotate(realImage, 90);
                        } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("8")){
                            realImage= rotate(realImage, 270);
                        } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("3")){
                            realImage= rotate(realImage, 180);
                        } else if(exif.getAttribute(ExifInterface.TAG_ORIENTATION).equalsIgnoreCase("0")){
                            realImage= rotate(realImage, 90); //Always gets in here
                        }

                        boolean bo = realImage.compress(Bitmap.CompressFormat.JPEG, 100, fos);

                        fos.close();


                        Log.d("Info", bo + "");

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

我遇到的问题是,TAG_ORIENTATION无论我如何握住我的设备,似乎总是为 0。我目前使用 HTC 进行测试。我应该TAG_ORIENTATION手动设置还是什么?

并感谢反馈!谢谢

4

0 回答 0