question

JassimAlRahma-9056 avatar image
0 Votes"
JassimAlRahma-9056 asked ColeXia-MSFT commented

Share <Image> Source using Essentials' Share

Hi

How can I Share <Image>'s Source using Xamarin Essentials Share?


Thanks,
Jassim

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

ColeXia-MSFT avatar image
0 Votes"
ColeXia-MSFT answered ColeXia-MSFT commented

Hello,

Welcome to Microsoft Q&A!

It depends on where the image comes from .

  • If the image is available on internet , we can just share the link .

await Share.RequestAsync(new ShareTextRequest
{
     Uri = uri,
     Title = "Image Link"
});


  • If the image is from internal storage , we can share the file according to the path.

await Share.RequestAsync(new ShareFileRequest
{
    Title = Title,
    File = new ShareFile(file)
});


  • If the image is from Embedded resource(shared project ) , we can get the stream from the file and save it into file , and then share the file .


     //read stream from bundle
         var assembly = IntrospectionExtensions.GetTypeInfo(typeof(App)).Assembly;
         Stream stream = assembly.GetManifestResourceStream("FormsA.dog2.png");
            
         //save data into file
         var documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
         documentsPath = Path.Combine(documentsPath, "Share");
         Directory.CreateDirectory(documentsPath);
            
         string filePath = Path.Combine(documentsPath, "share.png");
            
         byte[] bArray = new byte[stream.Length];
         using (FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate))
         {
             using (stream)
             {
                  stream.Read(bArray, 0, (int)stream.Length);
             }
             int length = bArray.Length;
             fs.Write(bArray, 0, length);
          }
            
            
         //share from file
         await Share.RequestAsync(new ShareFileRequest
         {
              Title = Title,
               File = new ShareFile(filePath)
          }); 
    

Best Regards,
Cole Xia


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.











· 2
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.

The message is from URL but is it set a Source for image control.

i don't want to share it as URL, I want to share it as an Image on Whatsapp.

Can I take the image from Source and Share it as an Image?

0 Votes 0 ·

No , the plugin only supports to share text and file , image source is not supported.

0 Votes 0 ·