从相机拍摄的图像在某些设备上旋转

时间:2019-10-02 09:15:09

标签: android camera image-rotation

在我的应用中,用户从相机或图库中获取图像,然后将这些图像转换为PDF 现在我的问题是在某些设备上,相机捕获的图像旋转了90度,这些设备是一些三星设备,特别是S7,

这是我调用所选图像并将其转换为PDF的地方

      PdfDocument document=new PdfDocument();
        // crate a page description
        PdfDocument.PageInfo pageInfo;
        PdfDocument.Page page;
        Canvas canvas;
        int i;
Bitmap image;



        for (i=0; i < list.size(); i++)  {


            pageInfo=new PdfDocument.PageInfo.Builder(992, 1432, 1).create();
            page=document.startPage(pageInfo);
            canvas=page.getCanvas();
            image=BitmapFactory.decodeFile(list.get(i));
            image = Bitmap.createScaledBitmap(image, 980, 1420, true);
            image.setDensity(DisplayMetrics.DENSITY_300);
            canvas.setDensity(DisplayMetrics.DENSITY_300);
            canvas.drawBitmap(image, 0, 0, null);
            document.finishPage(page);
        }
        @SuppressWarnings("deprecation") String directory_path=Environment.getExternalStorageDirectory().getPath() + "/mypdf/";
            File file=new File(directory_path);
            if (!file.exists()) {
                //noinspection ResultOfMethodCallIgnored
                file.mkdirs();
            }
            @SuppressLint("SimpleDateFormat") String timeStamp=(new SimpleDateFormat("yyyyMMdd_HHmmss")).format(new Date());
            String targetPdf=directory_path + timeStamp + ".pdf";
            File filePath=new File(targetPdf);
            try {
                document.writeTo(new FileOutputStream(filePath));

            } catch (IOException e) {
                Log.e("main", "error " + e.toString());
                Toasty.error(this, "Error making PDF" + e.toString(), Toast.LENGTH_LONG).show();
            }
            // close the document
            document.close();

0 个答案:

没有答案