Quantcast
Channel: WriteableBitmapEx
Viewing all articles
Browse latest Browse all 360

New Post: FromByteArray example

$
0
0
Hi all

I am creating a byte[] using ToByteArray (see ToByteArray Snippet), but when I try to reconstitute this into a WritableBitmap (see FromByteArray Snippet) I get an ArgumentException complaining about array out of bounds. I think the resize from 1,1 to the original image size is failing. But I am not sure what I am doing wrong. Any ideas?

Rob

FromByteArray Snippet

foreach (byte[] binary in Model.Client.Photos)
{
WriteableBitmap wbmp = BitmapFactory.New(1, 1).FromByteArray(binary);
}

ToByteArray Snippet

StorageFile file = await openPicker.PickSingleFileAsync();
        // If the file path and name is entered properly, and user has not tapped 'cancel'..
        if (file != null)
        {
            var property = await file.Properties.GetImagePropertiesAsync();

            WriteableBitmap wb = new WriteableBitmap((int)property.Width, (int)property.Height);

            using (IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
            {
                await wb.SetSourceAsync(fileStream);
                byte[] binaryImage = wb.ToByteArray();
                Model.Client.Photos.Add(binaryImage);
            }
        }

Viewing all articles
Browse latest Browse all 360

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>