Xamarin Forms image not showing

后端 未结 5 1399
孤街浪徒
孤街浪徒 2020-12-18 22:11

I have a Xamarin Forms (2.0) Android app where I\'m trying to show an image. I\'ve got an icon called icon-pages-r1.png which I\'m trying to show using the foll

5条回答
  •  误落风尘
    2020-12-18 22:53

    I had this issue.I set MSBuild project build output verbosity as Diagnostic. Now I found the following in my Output window when I searched for OOM.

    ImageRenderer: Error loading image: Java.Lang.OutOfMemoryError: Failed to allocate a 571513228 byte allocation with 2140744 free bytes and 92MB until OOM

    Now tried

    • Create a png image which has less than 200KB size and less than 1400 X 1050 size (for testing purpose).

    It worked fine.

    Note: "MSBuild project build output verbosity" can be found under Tools -> Options -> Projects and Solutions -> Build and Run

    General Checkpoints

    • Read Local Images
    • Make sure the file name has only lowercase alphabets.
    • Add that png file into Resources/drawable folder.

    Create a content page as follows

    
        
    
    • Clean solution.
    • Clean bin and Obj files.

    Resources says:

    Android supports bitmap files in three formats: .png (preferred), .jpg (acceptable), .gif (discouraged).

    Compress PNG and JPEG files says:

    You can reduce PNG file sizes without losing image quality using tools like pngcrush, pngquant, or zopflipng. All of these tools can reduce PNG file size while preserving the perceptive image quality.

    The pngcrush tool is particularly effective.

    To compress JPEG files, you can use tools like packJPG and guetzli.

    References:

    1. Android : Maximum allowed width & height of bitmap

    2. Android:java.lang.OutOfMemoryError: Failed to allocate a 23970828 byte allocation with 2097152 free bytes and 2MB until OOM

    3. Handling Bitmaps

提交回复
热议问题