0

I have this image in the xaml

Displaying image:

imageEntry.Source = ImageSource.FromStream(() =>
            {
                var stream = file.GetStream();
                file.Dispose();
                return stream;
            });

<Image x:Name="imageEntry" HeightRequest="240" />

I need to get that image and convert to bytearray to save in the db

async void OnSaveNoteButtonClicked(object sender, EventArgs args)
        {
            //Adding Note
            Image img = imageEntry;
            byte[] imgdata = ImageToByteArray(img);
            var N_Note = noteEntry.Text;
        }

public byte[] ImageToByteArray(System.Drawing.Image imageIn)
        {
            using (var ms = new MemoryStream())
            {
                imageIn.Save(ms, imageIn.RawFormat);
                return ms.ToArray();
            }
        }

But this not working. Cannot convert from 'Xamarin.Forms.Image to 'System.Drawing.Image'. Can someone advice whats best to do? Thank you.

Jen143
  • 815
  • 4
  • 17
  • 42
  • https://stackoverflow.com/questions/29122822/convert-xamarin-form-image-type-byte – EvZ May 17 '18 at 08:02
  • I need to get the image from xaml and need to convert to byte array – Jen143 May 17 '18 at 10:16
  • why do you want to store it as bytes? It will take more space than base64 which already takes more space than if you store it in the file system. Please choose what you need so I can answer your question – Ali123 May 17 '18 at 12:53
  • It is designed to store the image in the live db as byte and not in the file system – Jen143 May 17 '18 at 12:58
  • Hi @Ali123, I have requested to just save the db to file system, can you help me now how to do it? Thanks – Jen143 May 18 '18 at 03:01
  • Hi, you can convert it to `byte[]` by stream, look [this](https://stackoverflow.com/q/43499650/8632294) answer. – Robbit May 18 '18 at 08:50

0 Answers0