1

我有一个 Android 应用程序,我正在从图库中导入图像。它适用于所有图像,但对于某些大小超过 1.5 mb 的图像已更改其方向。我附上了该应用程序的图像。我正在使用此代码。

    newImage=(ImageView)findViewById(R.id.newImage);
    imagePath = getIntent().getStringExtra("ImagePath");
    try {
            ExifInterface exif = new ExifInterface(imagePath);
            orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1);
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

try{
            BitmapFactory.Options options=new BitmapFactory.Options();
            options.inJustDecodeBounds=true;
            InputStream is=new FileInputStream(new File(imagePath) );

            Display display = getWindowManager().getDefaultDisplay();
             final Point point = new Point();
                try {
                    display.getSize(point);
                } catch (java.lang.NoSuchMethodError ignore) { // Older device
                    point.x = display.getWidth();
                    point.y = display.getHeight();
                }

            int scrWidth = point.x;
            int scrHeight = point.y;
            originalBitmap=BitmapFactory.decodeStream(is,null,options);
            int imageWidth = options.outWidth;
            int imageHeight = options.outHeight;


            if(imageHeight>imageWidth){
                int newWidth=(scrWidth/2);
                int newHeight=(int)((float)imageHeight*((float)newWidth/(float)imageWidth));
                originalBitmap=BitmapLoader.loadBitmap(imagePath, newWidth, newHeight);
            }else{
                int newWidth=(scrWidth/2);
                //int newHeight=imageHeight*(imageWidth/newWidth);
                int newHeight=(int)((float)imageHeight*((float)imageWidth/(float)newWidth));

                originalBitmap=BitmapLoader.loadBitmap(imagePath, newWidth, newHeight);
            }

            is.close();


            //originalBitmap= Bitmap.createBitmap(originalBitmap, 0, 0, originalBitmap.getWidth(), originalBitmap.getHeight(), matrix, true);
            newBitmap=originalBitmap;

            options.inJustDecodeBounds=true;

            temp=BitmapLoader.loadBitmap(imagePath, 1200, 1200);
        }
        catch (Exception e) {
            // TODO: handle exception
        }
        if(originalBitmap!=null)
            //originalImage.setImageBitmap(originalBitmap);

        if(newBitmap!=null)
            newImage.setImageBitmap(newBitmap);
    }

图片

4

0 回答 0