Convert SfAvatarView to an image

Hi!

I would like to use the SfAvatarView to create an avatar (user edits and creates its own avatar in the app), when the avatar is done, I want to use that inside sfchat view (on both sender and reciver side).

SfSchat uses a Author class, in that class there is a property called Avatar of the type ImageSource. 

So the only way I see this to work is to create a image from SfAvatarView and attach that to the ImageSource that is in the Author class.

1. So, is this the best way to go (the image needs to be sent to a reciver-side anyway)?
2, If so, how do I create a an image (ImageSource) of the avatar that was made using SfAvatarView?

The image can exists only in memory, don't need to save it to the gallery, the image will later be converted to string and saved to a specific app repository.

6 Replies

SS Suganya Sethuraman Syncfusion Team January 4, 2021 10:00 AM UTC

Hi Ulf,

Greetings from Syncfusion.

We have analyzed your requirement. We would like to let you know that SfAvatarView is not an ImageControl, so we could not save the control as image and it is not possible to achieve your requirement using SfAvatarView.

Please let us know if you have any other concerns.

Regards,
Suganya Sethuraman.
 



UJ Ulf J January 4, 2021 03:40 PM UTC

Hi!

Ok, that is too bad..so its not possible to use the avatar control to generate an image for others..

I mean, you want to show your avatar on the receiver side of your chat msg., if you chat between two mobile apps, you can send meta-info and rebuild it again, but if you chat with another client app, like wpf client,  then you can't show the avatar. as there is no avatar control on wpf..

I really like your avatar control, but to make it more useful then displaying an image (I mean so the user can create their own avatar) it would be great if this function could be added.

Is there no way to come around this problem?


UJ Ulf J January 4, 2021 11:34 PM UTC

Hi again!

I found a way to create an image of the avatar by using SkiaSharp, basically recreating what SfAvatarView does..

So the user creates the avatar by using SfAvatarView, when its done, I use all these settings the user selected and provide them to SkiaSharp, and then SkiaSharp generates the image, so no communication between SfAvatarView and SkiSharp other then color parameters, recourse stream and text.

So, the text, background color and gradient colors is now supported, and I also extract the AvatarCharacter from your embedded resource, so, now I can replicate the SfAvatarView and create my image using SkiaSharp.



SS Suganya Sethuraman Syncfusion Team January 5, 2021 06:46 AM UTC

Hi Ulf,

Thanks for the update.

Please get back to us if you need any other assistance.

Regards,
Suganya Sethuraman.
 



UJ Ulf J January 6, 2021 02:33 PM UTC

If someone else wants to do the same, I based the SkiaSharp code from this blog.

https://itnext.io/create-iconic-text-avatars-using-skiasharp-and-xamarin-forms-e1334ae263d8


SS Suganya Sethuraman Syncfusion Team January 7, 2021 05:18 AM UTC

Hi Ulf,

Thanks for your suggestion.

Regards,
Suganya Sethuraman.
 


Loader.
Up arrow icon