ByoxCode / DrawView

Android view that allows the user to create drawings. Customize settings like color, width or tools. Undo or redo actions. Zoom into DrawView and add a background.
847 stars 156 forks source link

java.lang.IllegalArgumentException: width and height must be > 0 #30

Open tnylee opened 5 years ago

tnylee commented 5 years ago

Thank you for such an awesome library! Its helping me. However, an error occured while using it and I'd like to know if you can help me. Thanks!

java.lang.IllegalArgumentException: width and height must be > 0

Crashes on line drawingView.setBackgroundImage(editingImage, BackgroundType.FILE, BackgroundScale.CENTER_INSIDE);

If removed, no error occurs.

My XML:

<com.byox.drawview.views.DrawView
            android:id="@+id/drawingView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:dv_draw_corners="round"
            app:dv_draw_tool="pen"
            app:dv_draw_enable_zoom="true"
            app:dv_draw_max_zoom_factor="15"
            app:dv_draw_alpha="255"
            app:dv_draw_width="10"/>

configuration code:

drawingView = (DrawView) findViewById(R.id.drawingView);
drawingView.setBackgroundImage(editingImage, BackgroundType.FILE, BackgroundScale.CENTER_CROP);
drawingView.setDrawColor(getResources().getColor(R.color.colorPickerDefault))
                .setZoomEnabled(true)
                .setMaxZoomFactor(15)
                .setDrawAlpha(255)
                .setDrawWidth(maxPenSize);
drawingView.setBackgroundImage(editingImage, BackgroundType.FILE, BackgroundScale.CENTER_INSIDE);

What am I doing wrong?

aurasphere commented 5 years ago

Same problem here

ByoxCode commented 5 years ago

I recently update snapshot version, please use it and tell me if the problem persists

aurasphere commented 5 years ago

Tried with the 1.0.2. The error is gone but the background image is not set. This is my code (Kotlin):

override fun onCreate(savedInstanceState: Bundle?) {
  super.onCreate(savedInstanceState)
  setContentView(R.layout.activity_edit_picture)

  val imagePath = intent.getStringExtra("imagePath")
  edit_picture_view.backgroundImage(File(imagePath), BackgroundType.FILE, BackgroundScale.CENTER_INSIDE, 50)
}
ArronSingh commented 5 years ago

Hi,

Just an fyi the same error manifests on line with code: "mZoomRegionView.drawZoomRegion(mContentBitmap, mCanvasClipBounds, 4);"

If you add a delay there is no error and it prevents the crash: new Handler().postDelayed(new Runnable() { @Override public void run() { mZoomRegionView.drawZoomRegion(mContentBitmap, mCanvasClipBounds, 4); } }, 1000);

Could you add this to the next version please?

Best wishes,

Arron

MFam commented 4 years ago

I have a solution.

drawingView.post { drawingView.setBackgroundImage(File(uri.path), BackgroundType.FILE, BackgroundScale.CENTER_INSIDE) }

salario07 commented 3 years ago

thanks to byox great project, I cloned the project and fixed this bug. feel free to use it. implementation 'com.github.salario07:DrawView:1.0.4'

also see latest version from here: https://jitpack.io/#salario07/DrawView