Appending picture as byte[]

Hi!

I've been trying to append pictures to the word document generated by DocIO without much success. From what I understood, in Xamarin we must do this by using a byte[] that is the result of an image conversion. I've searched the forums for a way of converting an image located on the drawable file (in Android) and the using the AppendPicture.

The closer I've managed to get was this:

WordDocument localdocumento = new WordDocument();

IWSection localSection = localdocumento.AddSection();

IWParagraph localparagraph = localSection.AddParagraph();

ImageSource imagem = ImageSource.FromFile("MyLogo.jpg");     //This file is located on Android's drawable file path
byte[] localbyte = Encoding.UTF8.GetBytes(imagem.ToString());

IWPicture localpicture = localparagraph.AppendPicture(localbyte);

But the image file doesn't work properly. I've also tried using FFImageLoading library, but it didn't work as well (it gives me a null reference). Is there a simple way of achieving this on xamarin forms? Any help is appreciated!

3 Replies

DB Dilli Babu Nandha Gopal Syncfusion Team August 14, 2018 03:30 PM UTC

Hi Raelson, 

We appreciate your patience. 

We have prepared a sample based on your requirement. The sample can be downloaded from the following link 

Please let us know if the sample fulfills your requirement. 

Regards, 
Dilli babu 



RC Raelson Craftz August 14, 2018 04:45 PM UTC

Yes! It solves my problem. I was more or less aware of what I needed to do, but I couldn't find a clear tutorial on the internet. And this sample solves it. Thanks a lot!


DB Dilli Babu Nandha Gopal Syncfusion Team August 15, 2018 05:30 AM UTC

Hi Raelson, 

We are glad to know that the sample fulfills your requirement. Please let us know if you need any further assistance on this. 
  
Regards, 
Dilli babu. 


Loader.
Up arrow icon