Git Product home page Git Product logo

Comments (5)

yasirkula avatar yasirkula commented on July 26, 2024

Hi! It seems as if NativeGallery returns the image's path before it is written to the disk/while it is being written to the disk, but AFAIK this line ensures that image is written to the disk synchronously: https://github.com/yasirkula/UnityNativeGallery/blob/master/Plugins/NativeGallery/iOS/NativeGallery.mm#L482

Can you see any error messages in Xcode console? If you use the example code to display the selected image on a cube without using the ImageCropper plugin, does everything work properly?

from unitynativegallery.

andersonaraujodl avatar andersonaraujodl commented on July 26, 2024

Thanks for you reply!
I'll try to make the suggested modification without the ImageCropper and will get back to you ASAP!

from unitynativegallery.

andersonaraujodl avatar andersonaraujodl commented on July 26, 2024

Well, I've got a feedback: did all the tests and realized that there is something wrong with my logic (just couldn't figure out why it works perfect on Android and not on iOS). I'm attaching the sample bellow to see if there's something you can help with.

private IEnumerator CropPic()
    {
        yield return new WaitForEndOfFrame();

        bool ovalSelection = false;
        bool autoZoom = true;

        float minAspectRatio = 1, maxAspectRatio = 1;

        NativeGallery.Permission permission = NativeGallery.GetImageFromGallery((path) =>
        {
            Debug.Log("Image path: " + path);
            if (path != null)
            {
                // Create Texture from selected image
                texture = NativeGallery.LoadImageAtPath(path, 1024);

                if (texture == null)
                {
                    Debug.Log("Couldn't load texture from " + path);
                    return;
                }

                if (ImageCropper.Instance.IsOpen)
                    return;
            }
        }, LanguageManager.GetTranslation("SelectImage"), "image/png", 1024);

        newProfileInstance.previousTexture = (Texture2D) newProfileInstance.profileImage.texture;

        // If image cropper is already open, do nothing
        if (ImageCropper.Instance.IsOpen)
            ImageCropper.Instance.Hide();

        ImageCropper.Instance.Show(texture, (bool result, Texture originalImage, Texture2D croppedImage) =>
        {
            if (result)
            {
                newProfileInstance.profileImage.texture = croppedImage;

                if (croppedImage != null)
                {
                    newProfileInstance.UploadImage(ConvertImageToBytes(MakeTextureReadable(croppedImage)), croppedImage);
                    croppedTexture = croppedImage;
                }
            }
            else
            {
                croppedTexture = null;
            }
        },
        settings: new ImageCropper.Settings()
        {
            ovalSelection = ovalSelection,
            autoZoomEnabled = autoZoom,
            imageBackground = Color.clear, // transparent background
                selectionMinAspectRatio = minAspectRatio,
            selectionMaxAspectRatio = maxAspectRatio

        },
        croppedImageResizePolicy: (ref int width, ref int height) =>
        {
                //width /= 2;
                //height /= 2;
        });
    }

from unitynativegallery.

yasirkula avatar yasirkula commented on July 26, 2024

Oh, I see. You should just move ImageCropper.Instance.Show (in other words, all the code) into the callback function of NativeGallery.GetImageFromGallery, because the callback function is asynchronous on iOS and in your case, the assignation of the texture variable takes place after the ImageCropper.Instance.Show call.

from unitynativegallery.

andersonaraujodl avatar andersonaraujodl commented on July 26, 2024

It worked perfectly! I appreciate your work and your help! Thanks a lot!

from unitynativegallery.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.