简体   繁体   English

为什么保存图片时会出错?

[英]Why do I get an error when saving an image?

please tell me why I get this error?请告诉我为什么会出现此错误?

java.lang.IllegalArgumentException: x + width must be <= bitmap.width()

The error refers to the line below.错误指的是下面的行。 An error occurs when saving the image after editing:编辑后保存图像时出现错误:

surfaceView = new PhotoEditor(this, bitmap, arrowArrayList);
                setContentView(surfaceView);

My java code:我的 java 代码:

 relativeLayoutPhoto = findViewById(R.id.relativeLayoutPhoto);
        SharedPreferences sharedPreferences;
        int width;
        int height;
        float ratioToMedium;
        sharedPreferences = this.getSharedPreferences(SHARED_PREFERENCES_DISPLAY, Context.MODE_PRIVATE);
        width = sharedPreferences.getInt(WIDTH_KEY, 0);
        height = sharedPreferences.getInt(HEIGHT_KEY, 0);
        ratioToMedium = sharedPreferences.getFloat(RATIO_TO_MEDIUM_KEY, 0);

        Bitmap b = Bitmap.createScaledBitmap(bitmap, width, (int) (height - toolBarHeight * ratioToMedium),false);
        Drawable drawable = new BitmapDrawable(getResources(), b);
        relativeLayoutPhoto.setBackground(drawable);
        relativeLayoutPhoto.setOnDragListener(this);

Can you write your bitmap width and height and also values of every argument in this method?你能写出你的bitmap宽度和高度以及这个方法中每个参数的值吗?

Bitmap b = Bitmap.createScaledBitmap(bitmap, width, (int) (height - toolBarHeight * ratioToMedium),false);

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

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