简体   繁体   English

java.lang.ArithmeticException:从选择库压缩图像时除以零

[英]java.lang.ArithmeticException: divide by zero when compress image from pick gallery

I'm getting error java.lang.ArithmeticException: divide by zero when compress image from pick gallery.我收到错误java.lang.ArithmeticException: divide by zero当从选择库压缩图像时java.lang.ArithmeticException: divide by zero this Is my code:这是我的代码:

 public String compressImage(String filePath, String outputFilename) {

        Bitmap scaledBitmap = null;

        BitmapFactory.Options options = new BitmapFactory.Options();

        options.inJustDecodeBounds = true;
        Bitmap bmp = BitmapFactory.decodeFile(filePath, options);

        int actualHeight = options.outHeight;
        int actualWidth = options.outWidth;
        Log.i("INFO", "ActualHeight Input: " + actualHeight);
        Log.i("INFO", "ActualWidth Input: " + actualWidth);

        float maxHeight = 816.0f;
        float maxWidth = 612.0f;
        float imgRatio = actualWidth / actualHeight;
        float maxRatio = maxWidth / maxHeight;


       ............

        return outputFilename;
    }

the error get in lin : float imgRatio = actualWidth / actualHeight; lin 中的错误: float imgRatio = actualWidth / actualHeight; so how to fix it?那么如何解决呢?

The fact that you are getting the exception says that division by zero is occurring, and that options.outHeight is returning zero.您收到异常的事实表明正在发生除以零,并且options.outHeight返回零。 You need to find out why that is happening.您需要找出发生这种情况的原因。 If Log.i("INFO", "ActualHeight Input: " + actualHeight); If Log.i("INFO", "ActualHeight Input: " + actualHeight); returns you something other than null , provide us more details.返回null以外的其他内容,请向我们提供更多详细信息。

Please add the below line on your manifest (inside the Application block).请在您的清单中添加以下行(在 Application 块内)。

Android: requestLegacyExternalStorage = "true"安卓:requestLegacyExternalStorage = "true"

Hope, this will be helpful on this issue.希望,这将有助于解决这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM