Hi
How can I Share <Image>'s Source using Xamarin Essentials Share?
Thanks,
Jassim
Hi
How can I Share <Image>'s Source using Xamarin Essentials Share?
Thanks,
Jassim
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.
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?
No , the plugin only supports to share text and file , image source is not supported.
7 people are following this question.