Click here to Skip to main content
13,052,641 members (59,999 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


7 bookmarked
Posted 5 Aug 2014

Conversion between File, Byte , Stream,BitmapImage and WriteableBitmap

, 5 Aug 2014
Rate this:
Please Sign up or sign in to vote.
This tip resume the majority types of conversion that we need while developing


While developing , we need sometimes to convert the Image in many types then we can modify them as we want or to store them in a Database...

Using the code

1-Convert File to Byte[]

            byte[] fileBytes = null;
            if (file != null)
                using (IRandomAccessStreamWithContentType stream = await file.OpenReadAsync())
                    fileBytes = new byte[stream.Size];
                    using (DataReader reader = new DataReader(stream))
                        await reader.LoadAsync((uint)stream.Size);

2-Convert Byte[] to BitmapImage

using (InMemoryRandomAccessStream ms = new InMemoryRandomAccessStream())
                    using (DataWriter writer = new DataWriter(ms.GetOutputStreamAt(0)))

                    var image = new BitmapImage();

3-Convert Byte[] to Stream

Stream stream = new MemoryStream(fileBytes);

4-Convert  Stream to WriteableBitmap

WriteableBitmap writimage = new WriteableBitmap(1, 1);
BitmapPixelFormat format = BitmapPixelFormat.Unknown;

writimage = await WriteableBitmapExtensions.FromStream(writimage, stream, format);

5-Convert  File to BitmapImage

BitmapImage bmpImage = new BitmapImage(new Uri(file.Path));


these conversions can facilitate your work , you will find what you need with only one page ;)


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Anis Derbel
Software Developer (Junior) Microsoft Student Partners
Tunisia Tunisia
I study Software Engineering , 23 years old , I'm motivated with all Technologies of Microsoft.
Since I have been in the Community of Microsoft as Microsoft Student Partners, I developped many apps on the platform Windows and Phone. Now , it's time to share what I learn here and I'am ready to help Everyone.
You can contact me at any time (
Group type: Organisation

9 members

You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170713.1 | Last Updated 5 Aug 2014
Article Copyright 2014 by Anis Derbel
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid