Is it possible to use Image Set in a Xamarin Forms - image

I am trying to add some Images as Image Sets in a Xamarin.Forms project. I followed this guide . But the icon is not displayed. Is it possible actually to use Image Sets in a Xamarin Forms Solution for the iOS project?
<Image VerticalOptions="Center"
HorizontalOptions="End"
Source="check_outline_500_active.png"
WidthRequest="40">
</Image>

Yes you can.
create the Asset catalog
add Image Set and name it "check_outline_500_active" (without .png)
add the images
done
my xaml
<Image VerticalOptions="Center"
HorizontalOptions="Center"
Source="check_outline_500_active.png">
</Image>
Result
Note
You might have to delete mtbs (on the mac) and bin/obj (on your project) or the build cache can fool you :)

Try to add images in resources folder under xamarin ios project and rename file like :
check_outline_500_active.png,
check_outline_500_active#2x.png,
check_outline_500_active#3x.png
but in code use : check_outline_500_active.png

Related

Xamarin.Forms Images not showing

I am developing a Cross-Platform app in Xamarin Visual Studio 2019 and having issues with image display.
I am trying to show an image with the following XAML code.
<StackLayout Grid.Row="0" Grid.Column="0" Spacing="0" >
<Image
HorizontalOptions="CenterAndExpand"
VerticalOptions="CenterAndExpand"
Source="logo"
WidthRequest="{OnPlatform iOS=300, Android=250}">
</Image>
</StackLayout>
Problem is image not displaying on either preview or deployed app.
I took references from multiple forums including help from StackOverflow but couldn't tackle the issue.
Here are the points and methods I worked on to resolve the issue.
The file named logo is an android resource folder and is a proper .png file.
Property for the file is set to AndroidResource.
As per answers posted here, Xamarin Images not showing, file name does not have a hyphen in it, and also tried other posted answers on the same page.
Image size 307X80 pixels so it's well within range for memory or size.
Android Drawable folder also contain default xamarin_logo.png image and that file works fine. But not newly added images. Is there anything I am missing here to add these image files to the solution?
Either the image extension or image path or the build action for the image seems to be the problem in your case. I tried your code and got that working fine for both png and jpg images.
<StackLayout Spacing="0">
<Image HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand"
Source="github.png" WidthRequest="{OnPlatform iOS=300, Android=250}" />
<Image HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand"
Source="githubb.jpg" WidthRequest="{OnPlatform iOS=300, Android=250}" />
</StackLayout>
Note: I have removed the grid.row and grid.column indexing as I am not using my StackLayout inside a grid.
Please make sure whether you have kept your images directly inside the drawable folder in the Resources in Android. If not, you may have to give the Source name as FolderName\ImageName.Extension.
Refer below link for more details:
https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/images?tabs=windows#local-images
Also, please ensure whether the BuildAction of your image is AndroidResource and Custom Tool is MSBuild:UpdateGeneratedFiles. Please refer to the below image.
I got the below output for the code which I posted above.
I hope that helps.
Your XAML code is Correct but you have missed the image extension .png you must define your image Extension(format) Ex: (image.png or image.jpeg) That is the reason the image is not displayed.
<StackLayout Grid.Row="0" Grid.Column="0" Spacing="0" >
<Image
HorizontalOptions="CenterAndExpand"
VerticalOptions="CenterAndExpand"
Source="logo.png"
WidthRequest="{OnPlatform iOS=300, Android=250}">
</Image>
</StackLayout>

To create SlidingupPanel like googleMaps for both android and IOS

Do you know how to create a SlideUpPanel like GoogleMaps for both Android and iOS using Xamarin?
If I use SliddingupPanel layout is only for android
Help me, please.
I would suggest you use DKSlideUpPanel
It's easy to use and fast
Steps:
First, simply reference the NuGet package in your Xamrin.Forms projects.
Second, initialize SlidingUpPanel instance either in XAML or C#.
Lastly, apply the SlidingPanelConfig for your customizations.
How to use:
Add a mainView something like this;
<DK:SlidingUpPanel x:Name="spTest">
<DK:SlidingUpPanel.MainView>
<StackLayout Orientation="Horizontal" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
**MainDesign**
</StackLayout>
</DK:SlidingUpPanel.MainView>
Set panel ratio and if you want the toolbar visible:
<DK:SlidingUpPanel.PanelRatio>0.4</DK:SlidingUpPanel.PanelRatio>
<DK:SlidingUpPanel.HideNavBar>True</DK:SlidingUpPanel.HideNavBar>
Check the following guide for an even better understanding of how it works:
https://www.c-sharpcorner.com/article/xamarin-forms-slideuppanel-app/

Xamarin.Forms iOS images not showing

I have a Xamarin.Forms shared project. On Android all images work fine. I wanted to add them to my iOS project, but they don't show. I've added them to Assets.xcassets:
{
"filename": "logo_launcher.png",
"scale": "1x",
"idiom": "universal"
}
And I use the following XAML:
<Image Source="logo_launcher.png" x:Name="logo" />
I've added all images except for the vector ones. I'm testing it on a iPhone 8 - 11.4 simulator.
Although it is deprecated, I tried to add the images to the "Resource" folder. But I couldn't even select the .png files. So that didn't work either.
I'm lost at what to do. Is there some option I need to enable, or something to include in the XAML to make it work?
Just select all images in resources folder in ios and right click-->build action-->bundle resource. It will work.
Check/Reproduce some steps below:
Check the build action on your image resource, in shared PCL it should be Embedded Resource, in Android the build action should be AndroidResourceand BundleResource in iOS
Try to set Copy to output directory to Always copy
Delete bin/obj folders, switch build configuration from debug to release, rebuild project and then back to debug
Try to delete the image from iOS, rebuild, re-add again, and then repeat the steps above
Also, you can try to set the ImageSource as you can see below:
<Image x:Name="logo">
<Image.Source>
<OnPlatform x:TypeArguments="ImageSource">
<On Platform="Android" Value="logo_launcher.png"/>
<On Platform="iOS" Value="logo_launcher"/>
</OnPlatform>
</Image.Source>
</Image>
I hope this can help you.
Maybe I found a possible solution using Assets.xcassets, check the steps below:
Main.xaml
<Image x:Name="iconBrain">
<Image.Source>
<OnPlatform x:TypeArguments="ImageSource">
<OnPlatform.iOS><FileImageSource File="IconBrain"/></OnPlatform.iOS>
<OnPlatform.Android><FileImageSource File="ic_brain"/></OnPlatform.Android>
</OnPlatform>
</Image.Source>
</Image>
Android: Add the images on the respective Drawable folders under Resourses directory.
iOS: Create a new Image Set under Assets.xcassets and add the Images.
Done. No extra properties, configs, or xamarin tricks.
Check out my GitHub for the full solution, also I tried to reproduce the same environment w/ Xamarin.Forms, Shared Project and iPhone 8 - 11.4 simulator.
Another point, you can't add the images under mipmap directories, because the mipmap folders are for placing your app/launcher icons (which are shown on the homescreen) in only. Any other drawable assets you use should be placed in the relevant drawable folders as before.
It’s best practice to place your app icons in mipmap- folders (not the drawable- folders) because they are used at resolutions different from the device’s current density. - Google blogpost
Finally, thank you for the information about the deprecated approach by Apple.
Prior to iOS 9, images were typically placed in the Resources folder with Build Action: BundleResource. However, this method of working with images in an iOS app has been deprecated by Apple. For more information, see Image Sizes and Filenames. - Images in Xamarin.Forms
I hope this can help you.

Image is not visible in android project with XAML forms - Xamarin even though provided solutions applied

I tried solutions from the following links but none worked.
where-to-put-images-for-xamarin-froms-application
developer.xamarin.com/guides/xamarin-forms/user-interface/images/#Local_Images
image-not-showing-in-xamarin-forms-app.html
I used below syntax
<Image Source="lock.png" HeightRequest="20" WidthRequest="20" HorizontalOptions="Center" VerticalOptions="Center" Grid.Row="0" Grid.Column="0"></Image>
Here is the image for where i've kept image
No image displays
Edit
These are the only things in my XAML page.
In my case the issue was of assembly.
when trying all the possible solutions like
1.) Changing Build Action
2.) Adding Image to all the folders within Resources
3.) Naming Convention should not include - in File/Image Name.
4.) Changing Background Color
I also got one solution while searching for embedded Images that assembly was missing here.
This change worked for me in using Local Images.
Got that solution from this link
Right click the lock.png image and see if there is an option "include in project"
If there is, project cannot find image
In my case I need to use method Forms.Init(Context activity, Bundle bundle), in my SplashScreen OnCreate method and Activity class OnCreate method. But it also important that images build action properties is set on AndroidResource.

Xamarin.Forms PCL cannot show image

I'm learning Xamarin.Forms PCL. I want to load image on page, i tried to load image with uri, that's OK. But i add image into project, it's don't work.
<StackLayout Margin="0,20,0,0">
<Image x:Name="img" Source="mario.jpg"/>
<Button x:Name="btnRotate" Clicked="btnRotate_Clicked" Text="Rotate" />
</StackLayout>
Any help is appreciated. Thanks!
You can not include dashes or spaces in image names for Android compatibility
Rename your image from piotr-chrobot-276746.jpg to something else, like piotrchrobot.jpg
https://developer.xamarin.com/guides/android/application_fundamentals/resources_in_android/part_1_-_android_resource_basics/
Don't forget to set the Build action to AndroidResource.

Resources