Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Creative [RELEASED] Image Cropper - multiplatform image cropping solution with oval mask support

Discussion in 'Tools In Progress' started by yasirkula, Apr 15, 2018.

  1. OldKing_Wang

    OldKing_Wang

    Joined:
    Jan 25, 2015
    Posts:
    43
    Hi yasirkula

    thanks for the good assets !

    recently I try to use ImageCropper in my URP project. I found out I can't crop any image. even the Demo scene return a empty result.

    so I look into the code . found out ImageCropper use the Layer 22 for the crop logic.

    Code (CSharp):
    1.        
    2.         cropRenderCanvas.gameObject.layer = 22; // some random layer that is hopefully not used by any other object
    3.         cropRenderImage.gameObject.layer = 22;
    4.         cropRenderCamera.cullingMask = 1 << 22;
    5.         cropRenderCanvas.gameObject.SetActive(false);
    6.  
    the reason I can't display anything is . in my Render Setting . the Main Filtering layer is set to Mixed.



    upload_2023-4-27_22-4-45.png

    so any layer that not select in the setting will not display.

    upload_2023-4-27_22-7-44.png

    it's easy fix . just named layer 22 and select it in the Filtering .


    I think maybe you can mention the Layer22 things in your document?

    anyway. it's really good asset. help me a lot.

    thanks!
     
  2. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,783
    Added that info to GitHub page now, thanks!
     
  3. gareth_untether

    gareth_untether

    Joined:
    Jan 5, 2018
    Posts:
    63
    Hey, I've been struggling with a WebGL project that takes a screenshot and crops it - the problem is that it works fine in the Editor, but in a web browser the crop position is wrong. I it's guess because of screen resizing even though I'm taking measurements from a rectTransform. I'm wondering if I can replace my code with your ImageCropper?

    My app takes a screenshot of the entire app, then crops a section. The size of the screenshot is scaled using ScreenCapture.CaptureScreenshotAsTexture(imageScale).

    Does ImageCropper play well with WebGL and changing screen sizes? Can you give any pointers to get started?

    Thank you!
     
  4. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,783
    I'd expect it to be consistent on all platforms. You can call ImageCropper.Instance.Show with desired selectionInitialPadding settings and then immediately follow it with this code:

    Texture2D croppedTexture = ImageCropper.Instance.CropSelection();
    ImageCropper.Instance.Hide();

    I haven't tried this approach though.
     
    gareth_untether likes this.
  5. dazaizone

    dazaizone

    Joined:
    Mar 6, 2020
    Posts:
    19
    Hello, it's been a long time, thanks for this , may I ask on how or is there anyway to make the cropper more flexible? not only squared shape? like how the native android image cropping behave? Thank you. more power.
     
  6. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,783
    @dazaizone Hi! Do you mean a mask in the shape of e.g. a rabbit? This is not supported built-in, yeah. I can't remember the source code in detail so I can't tell if there is a specific way to achieve this. Feel free to experiment though. PS. Rectangular, circular and ellipsis masks are supported built-in, if that's what you have in mind.
     
  7. dazaizone

    dazaizone

    Joined:
    Mar 6, 2020
    Posts:
    19
    Hello @yasirkula, based on the webGL sample and after importing the plugin, I can only drag the 4 corner of the cropper in a 'squared' cropping manner, any idea how to enable the built-in Rectangle cropping? for portrait image? I think I missed out something, sorry for the trouble and thank you. More power.
     
  8. dazaizone

    dazaizone

    Joined:
    Mar 6, 2020
    Posts:
    19
    I think this is the one I am looking @yasirkula, Thank you, I will try
     
    yasirkula likes this.