Compose an image and send to WeChat

I have a program that collects some text entered by users. I then convert these text into an image using SkiaSharpl and have the image saved in DCIM directory. The image and text have to be forwarded to WeChat.

I am using the following codes to send some text.

        await Xamarin.Essentials.Share.RequestAsync(new ShareTextRequest
        {
            Text = RegistrationText,
            Subject = $"My Subject {aSalesName}"
        });

Then manually lookup the image in the DCIM directory and then forward it out.

Here are my questions:

1/ Is there a way to simplify the operation? For example, combine two send actions into a simple click.
2/ Can I restrict the message recipient or even fix it, instead of letting the sender picking from the contact list?

contact leyThanks for your help.

Answers

  • LandLuLandLu Member, Xamarin Team Xamurai

    1/ Is there a way to simplify the operation? For example, combine two send actions into a simple click.

    Instead of storing the image in the photo gallery, you could save it to the app's local folder.
    Firstly, convert your image to bytes array. Then use WriteAllBytes to store data to the app's local folder:

    // Get the local folder path
    var folderPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
    var filePath = Path.Combine(folderPath, "image.png");
    // write operation
    File.WriteAllBytes(filePath, data);
    // Read operation
    File.ReadAllBytes(filePath);
    

    This won't show a picker window for user, you can store and retrieve images by the code above.

    2/ Can I restrict the message recipient or even fix it, instead of letting the sender picking from the contact list?

    If you are meaning you want to send the data to a particular user in the WeChat, I'm afraid we can't do that. As this process is controlled by WeChat, we can't change that behavior. It should be chosen by the users.

Sign In or Register to comment.