How can I add png images when I create a plugin?

I am developing a plugin for xamarin.I need to add the images to the plugin.There are several images which I will be able to add.How can I do this?.Those images are relevant to xaml pages which I gonna implement through plugin.please can anyone have an idea.I have tried lot of methods.firstly i made a class library but I could not add this images properly.Therefore I start to create a plugin.

Best Answers

  • AndyFlisherAndyFlisher ✭✭✭ GB ✭✭✭
    edited February 2018 Accepted Answer

    Don't have an example to hand, but the image Source should be something like;

    ImageSource.FromResource("$PROJECTNAME.$FOLDERNAME.$IMAGE.png")

    eg;

    ImageSource.FromResource("MyDemoProject.Resources.image1.png")

Answers

  • NayaniNayani ✭✭ Member ✭✭

    @AndyFlisher thanks . please can you give me an example for how to do it.Specially I should mention I am developing a library for xamarin.Forms portable project.

  • NayaniNayani ✭✭ Member ✭✭

    I have tried your both the methods. .But it does not work.

        public StackLayout testpage(int result,Color scolor,string imageName="ratingTransparent.png")
                {
                    var layout = new StackLayout();
                    var layout1 = new AbsoluteLayout() { WidthRequest = width, HeightRequest = hight, BackgroundColor = Color.Black, HorizontalOptions = LayoutOptions.Start, Margin = 0, };
                    var slayout = new StackLayout() { WidthRequest = RatingWidth(result), HeightRequest = hight, BackgroundColor = StarColor(scolor), HorizontalOptions = LayoutOptions.Start };
                    AbsoluteLayout.SetLayoutBounds(slayout, new Rectangle(0f, 0f, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize));
                    AbsoluteLayout.SetLayoutFlags(slayout, AbsoluteLayoutFlags.PositionProportional);
                    var image = new Image { Source = imageName, BackgroundColor = Color.Transparent };
                    AbsoluteLayout.SetLayoutBounds(image, new Rectangle(0f, 0f,width, hight));
                    AbsoluteLayout.SetLayoutFlags(image, AbsoluteLayoutFlags.PositionProportional);
    
                    layout1.Children.Add(slayout); 
                    layout1.Children.Add(image);
                    layout.Children.Add(layout1);
                    return layout;
                }
    

    this is the code what I used to add the image.(ratingTransparent.png)

  • NayaniNayani ✭✭ Member ✭✭

    @AndyFlisher .thanks for your answer.Both the methods were tried.But they were not working.can you please suggest anthor way to do it?

  • NayaniNayani ✭✭ Member ✭✭

    @AndyFlisher ,
    public StackLayout testpage(int result,Color scolor,string imageName="ratingTransparent.png")
    {
    var layout = new StackLayout();
    var layout1 = new AbsoluteLayout() { WidthRequest = width, HeightRequest = hight, BackgroundColor = Color.Black, HorizontalOptions = LayoutOptions.Start, Margin = 0, };
    var slayout = new StackLayout() { WidthRequest = RatingWidth(result), HeightRequest = hight, BackgroundColor = StarColor(scolor), HorizontalOptions = LayoutOptions.Start };
    AbsoluteLayout.SetLayoutBounds(slayout, new Rectangle(0f, 0f, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize));
    AbsoluteLayout.SetLayoutFlags(slayout, AbsoluteLayoutFlags.PositionProportional);
    var image = new Image { Source = imageName, BackgroundColor = Color.Transparent };
    AbsoluteLayout.SetLayoutBounds(image, new Rectangle(0f, 0f,width, hight));
    AbsoluteLayout.SetLayoutFlags(image, AbsoluteLayoutFlags.PositionProportional);

            layout1.Children.Add(slayout); 
            layout1.Children.Add(image);
            layout.Children.Add(layout1);
            return layout;
        }
    

    this is the code what I used to add the image.(ratingTransparent.png)

  • AndyFlisherAndyFlisher ✭✭✭ GBBeta, University ✭✭✭
    edited February 2018 Accepted Answer

    Don't have an example to hand, but the image Source should be something like;

    ImageSource.FromResource("$PROJECTNAME.$FOLDERNAME.$IMAGE.png")

    eg;

    ImageSource.FromResource("MyDemoProject.Resources.image1.png")

Sign In or Register to comment.