Skip to content
This repository has been archived by the owner on Apr 30, 2024. It is now read-only.

Cannot load file into cropView #6

Closed
rohanmahale opened this issue Nov 25, 2015 · 21 comments
Closed

Cannot load file into cropView #6

rohanmahale opened this issue Nov 25, 2015 · 21 comments
Labels

Comments

@rohanmahale
Copy link

Hi @davidbeloosesky , @eveliotc

I am trying to load an image into the cropview but it does not show up. I pass a string extra to my crop image activity.

I then try to load it into the cropview using the following

@AfterViews
void setupUI() {
    if (getIntent().getExtras() != null) {
        if (getIntent().getExtras().getString(KEY_IMAGE_FILE_PATH) != null) {
            cropView.extensions()
                    .load(Uri.fromFile(new File(getIntent().getStringExtra(KEY_IMAGE_FILE_PATH))));

        }
    }

}

The value of the string on debugging is

/storage/emulated/0/Pictures/PrismApp/Current/96adeca7-79a3-4cf9-bc1c-8c736bb26ee2.jpg

Why does the image not show up? Am I using the api wrong or is it a bug?

I have even tried removing the Uri.fromFile bit and directly loading a File.

I am not using the

cropView.extensions().load(galleryPictureUri);

Instead, I am using my own intent and request code to launch my CropImageActivity before returning to my current activity.

@eveliotc
Copy link
Contributor

@rohanmahale is PrismApp your own app? Or is a third-party app like Gallery? I'd start by making sure your app has read permission on that file.

If you do, to help us debug this please try loading that file on a regular ImageView using your Bitmap library of preference e.g. Picasso, Glide, etc.

@rohanmahale
Copy link
Author

Yup. I am using Glide. Prism is the name of my app.

@eveliotc
Copy link
Contributor

@rohanmahale cool, can you please try loading that file into a regular ImageView with Glide? Also I could take a look at this later today if you can provide me with that file and the version of Glide you are using

@rohanmahale
Copy link
Author

Yup..Done that. I can load images using glide both into regular image views as well as the crop view using Glide.with(...).load(...).into(...)
Glide version 3.6.1.

@rohanmahale
Copy link
Author

The idea was to launch my own intent to select a picture and then move onto the cropping activity i.e passing the data(uri or path string) as an extra via an intent to the cropping activity. Is it not possible to do this right now? I'm sure using

cropView.extensions().pickUsing(this, PICK_IMAGE_FROM_GALLERY);

works.

@eveliotc
Copy link
Contributor

@rohanmahale can you please send us a sample image for us to reproduce? evelio@lyft.com also what device are you using?

@rohanmahale
Copy link
Author

@eveliotc . I am using a Xiaomi Redmi 2. I dont think it has anything to do with the image.

Ok this is what I was trying to do. In my current activity I launch my own intent to pick an image either from the Gallery/Google Photos. On Picking that image I was getting the Uri which I would convert to a file path and pass to my CropImageActivity as an extra. In CropImageActivity I was using the

cropView.extensions()
                .load(new File(path));

I even kept a static Uri object in this activity, set it and then tried to load it. Neither method worked.

(I was trying to load without using the pickUsing() method )

@Modificator
Copy link

private void resetTouchManager() {
        final boolean invalidBitmap = bitmap == null;
        final int bitmapWidth = invalidBitmap ? 0 : bitmap.getWidth();
        final int bitmapHeight = invalidBitmap ? 0 : bitmap.getHeight();
        touchManager.resetFor(bitmapWidth, bitmapHeight, getWidth(), getHeight());
}

when load File to it, getWidth getHeight or getMeasured , come back zero

@juliusspencer
Copy link

I have the same problem, if trying to use pickUsing(), the image loads. If not it will not load. If I set the view to ImageView it loads.

@juliusspencer
Copy link

Ok I solved this by using a ViewTreeObserver combined with this commit:
https://github.com/lyft/scissors/pull/11/files

@rohanmahale
Copy link
Author

@juliusspencer . What was the purpose of the ViewTreeObserver? Could you elaborate? Also I'm guessing you've downloaded and added the library project separately and not just using it as a gradle
dependency.

@juliusspencer
Copy link

Yes I have pulled it down and made the modifications as per the pull request, then deployed to my own Synology server.

I used the ViewTreeObserver because Picasso (in my case) didn't seem to end up loading the image into the CropView. As soon as I used the ViewTreeObserver to wait for things to load it loaded the Image from the intent. I've been passing the Uri through as a Parcelable.

Hope that helps. :)

@rohanmahale
Copy link
Author

@juliusspencer Yup that definitely helps. Thanks! Could you show me the snippet of the ViewTreeoObserver portion . Do you load the image into the cropView in the onGlobalLayout callback(OnGlobalLayoutListener)?

@juliusspencer
Copy link

Yes that's correct:

        // load image
        ViewTreeObserver vto = mCropView.getViewTreeObserver();
        vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override public void onGlobalLayout() {
                mCropView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                mCropView.extensions().load(mGalleryPictureUri);
            }
        });

@eveliotc
Copy link
Contributor

@rohanmahale @Modificator issue is to call load before first layout pass has happened, this could be due e.g. calling load from Activity#onCreate at such point both view and viewport dimensions are always 0, as @juliusspencer mentioned fix would be to defer load call until view has proper dimensions.

As it seems a common pitfall I'll add a fix and deploy a new version shortly.

@rohanmahale
Copy link
Author

Thanks @eveliotc . I use AndroidAnnotations. So I am currently loading it in a method annotated with @AfterViews.

@eveliotc
Copy link
Contributor

@rohanmahale @Modificator @juliusspencer can you please use try #16 should be on latest snapshot:

compile 'com.lyft:scissors:1.0.2-SNAPSHOT'

Also you might have to add sonatype snapshots to your repository:

maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }

@eveliotc
Copy link
Contributor

eveliotc commented Dec 1, 2015

@rohanmahale @Modificator @juliusspencer did you get the chance of trying out that patch/snapshot?

@rohanmahale
Copy link
Author

@eveliotc I just tried it out. It seems to be working fine.

eveliotc added a commit that referenced this issue Dec 2, 2015
Fixes #6 Defer load until first layout pass
@eveliotc
Copy link
Contributor

eveliotc commented Dec 2, 2015

@rohanmahale thanks!

@rohanmahale
Copy link
Author

👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants