how to add jpg image to Ios project for Visual studio with xamarin.

AdeptusAdeptus TRMember ✭✭

Hello. I got a problem in my project in Visual studio with Xamarin. I want to add to images sets in IOS project's asset catalog a .jpg image. But VS allow me add ony png files. Is there any way to add .jpg image to use it in storyboard and in code.

Best Answer

  • JGoldbergerJGoldberger US Xamurai
    edited December 2017 Accepted Answer

    @Adeptus

    PNGs are the preferred image file format, but JPGs should work, and they do in Visual Studio for Mac, but I do see the issue in Visual Studio on Windows that only PNG files can be added (bug report filed)

    You can work around this with some manual editing. Try this:

    1. Change the extension of the JPG image file to PNG
    2. Add it to the Image Set via drag and drop or using the file browser
    3. Open File Explorer and navigate to the folder where your image is on the file system. (Should be in the Resources/*.xcassets/*.imageset folder)
    4. Change the image file extension back to JPG
    5. Open the Contents.json file in a text editor (like notepad) and look for the name of the image file you just added and change the extension to JPG.
    6. You will also need to edit the .csproj file in a text editor and again look for the name of the image file and change the extension to .jpg. (otherwise you will get a build error with a file not found as it is trying to look for the file with png extension)

    Alternately move your project to your Mac and add your JPGs to the image sets in Visual Studio for Mac and then move back to VS Windows.

Answers

  • seanydaseanyda GBMember ✭✭✭✭✭

    @Adeptus said:
    Hello. I got a problem in my project in Visual studio with Xamarin. I want to add to images sets in IOS project's asset catalog a .jpg image. But VS allow me add ony png files. Is there any way to add .jpg image to use it in storyboard and in code.

    To display images in Xamarin, You want to add them into your Resources folder for iOS and setting the Build Action as a "BundeResource". Or to use Images from the PCL, Set them as an EmbedddedResource.

    Refer here for more information:
    https://developer.xamarin.com/guides/xamarin-forms/user-interface/images/

    The Asset Catalogs are used for things like App Icons, Launch Screens etc.

  • AdeptusAdeptus TRMember ✭✭

    @seanyda said:
    To display images in Xamarin, You want to add them into your Resources folder for iOS and setting the Build Action as a "BundeResource". Or to use Images from the PCL, Set them as an EmbedddedResource.

    Refer here for more information:
    https://developer.xamarin.com/guides/xamarin-forms/user-interface/images/

    The Asset Catalogs are used for things like App Icons, Launch Screens etc.

    I use VisualStudio with Xamarin. Not Xamarin forms.

  • JGoldbergerJGoldberger USMember, Forum Administrator, Xamarin Team, University Xamurai
    edited December 2017 Accepted Answer

    @Adeptus

    PNGs are the preferred image file format, but JPGs should work, and they do in Visual Studio for Mac, but I do see the issue in Visual Studio on Windows that only PNG files can be added (bug report filed)

    You can work around this with some manual editing. Try this:

    1. Change the extension of the JPG image file to PNG
    2. Add it to the Image Set via drag and drop or using the file browser
    3. Open File Explorer and navigate to the folder where your image is on the file system. (Should be in the Resources/*.xcassets/*.imageset folder)
    4. Change the image file extension back to JPG
    5. Open the Contents.json file in a text editor (like notepad) and look for the name of the image file you just added and change the extension to JPG.
    6. You will also need to edit the .csproj file in a text editor and again look for the name of the image file and change the extension to .jpg. (otherwise you will get a build error with a file not found as it is trying to look for the file with png extension)

    Alternately move your project to your Mac and add your JPGs to the image sets in Visual Studio for Mac and then move back to VS Windows.

  • AdeptusAdeptus TRMember ✭✭

    Thank you.

Sign In or Register to comment.