Use byte array as BackgroundImage on TabbedPage

Hi

Is it posible to use a ByteArray as image source in tabbedPage.
I have a byte to imagevonverter

Answers

  • RalphShillingtonRalphShillington CAMember ✭✭

    Jasman, What did you end up doing for getting a byte[] as the background Image?

  • DotNetNinjaDotNetNinja DKMember

    Hi Ralph

    I ended up saving the bytes as an image on the device and the setting the backgroundImage to the newly saved image, after navigating away from the page the image is deleted.

    `

        async private void SaveImage(byte[] photo)
        {
            try
            {
                var bytes = photo; 
    
                localFilename = string.Format("{0}.png", Guid.NewGuid());
    

    if IOS

                string documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
                string localPath = Path.Combine(documentsPath, localFilename);
    
                File.WriteAllBytes (localPath, bytes); 
                this.BackgroundImage = localPath;
    

    endif

    if ANDROID

                string documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
                string localPath = Path.Combine(documentsPath, localFilename);
    
                File.WriteAllBytes(localPath, bytes);
    
                this.BackgroundImage = localPath;
    

    endif

    if WINDOWS_PHONE

                 StorageFolder picsFolder = ApplicationData.Current.LocalFolder;
                 StorageFile file = await picsFolder.CreateFileAsync(localFilename, CreationCollisionOption.ReplaceExisting);
    
                 var stream = await file.OpenAsync(FileAccessMode.ReadWrite);
    
                 using (var outputStream = stream.GetOutputStreamAt(0))
                 {
                     DataWriter writer = new DataWriter(outputStream);
                     writer.WriteBytes(bytes);
                     writer.StoreAsync();
                     outputStream.FlushAsync();
                 }
                 this.BackgroundImage = file.Path;
    

    endif

            }
            catch (Exception exception)
            {
    
                Debug.WriteLine(exception.Message);
            }
        }
    

    `

  • RalphShillingtonRalphShillington CAMember ✭✭

    Thanks. Certainly a work around but I'll give that approach a go.

Sign In or Register to comment.