question

Masha0307-7348 avatar image
0 Votes"
Masha0307-7348 asked WenyanZhang-MSFT edited

How to share the image from program to social media(Facebook,Telegram and other)?

Hello. I make a screenshot on page and I want to share it to social media. I do not know how to share image to the social media. I know only how to share text, but I need to share image.Please help me to share screenshot from program

  <ContentPage.Content>
         <StackLayout HeightRequest="30" WidthRequest="30">
    
             <StackLayout x:Name="header">
                 <Frame
                     Padding="3"
                     BackgroundColor="White"
                     BorderColor="#DBDBDB"
                     CornerRadius="15"
                     HasShadow="False">
                     <StackLayout Orientation="Horizontal">
                         <StackLayout
                             Margin="5,0,0,0"
                             HorizontalOptions="Start"
                             Orientation="Horizontal">
    
                             <StackLayout VerticalOptions="Center">
                                 <Label
                                     FontSize="16"
                                     HorizontalOptions="Start"
                                     Text="USD"
                                     TextColor="Black" />
                                 <Label
                                     FontSize="10"
                                     HorizontalOptions="Start"
                                     Text="US Dollar"
                                     TextColor="Black" />
                             </StackLayout>
    
    
                         </StackLayout>
    
                     </StackLayout>
                 </Frame>
             </StackLayout>
    
             <Button x:Name="ShareButton" Text="Share" />
             <Image x:Name="result" />
         </StackLayout>
     </ContentPage.Content>

 

  public async void Button_Clicked(Object o,EventArgs e)
         {
             var image =await header.CaptureImageAsync();
             result.Source = ImageSource.FromStream(() => image);
    
         }

It is code how I make screenshot.Please help me to share image from program to social media

dotnet-xamarin
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

WenyanZhang-MSFT avatar image
0 Votes"
WenyanZhang-MSFT answered WenyanZhang-MSFT edited

Hello,
Welcome to our Microsoft Q&A platform!
You can save image and then use Xamarin.Essentials Share like the following code

 string filePath = model.PhotoPath;//the path you saved
 string fileType = "image/jpeg";
 ShareFile fileToShare = new ShareFile(filePath, fileMimeType);
 ShareFileRequest shareRequest = new ShareFileRequest(fileToShare);
 await Share.RequestAsync(shareRequest);

For more information you can refer to:
https://github.com/xamarin/Essentials/issues/424

Best Regards,
Wenyan Zhang



If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.