how to create image file(named test.jpg) from InMemoryRandomAccessStream
-
Friday, March 16, 2012 2:23 AMhow to create image file(named test.jpg) from InMemoryRandomAccessStream in winrt with c#?
winRT
All Replies
-
Friday, March 16, 2012 1:51 PMModerator
Hi,
Please first call StorageFolder.CreateFileAsync to create test.jpg file.
Then call InMemoryRandomAccessStream.WriteAsync to write the stream into IBuffer.
Finally, call FileIO.WriteBufferAsync to write the buffer into the storagefile returned by the first step.
Please refer to File access sample for more details.
Best wishes,
Robin [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.

- Marked As Answer by Min ZhuMicrosoft Contingent Staff, Moderator Wednesday, March 21, 2012 2:51 AM
-
Saturday, March 17, 2012 1:40 AMModerator
Robin's answer assumes that your stream already contains the raw bits of the JPG file. If your data is not already in JPG format you can use the BitmapEncoder class to encode the bitmap data to JPG (and the BitmapDecoder to decode to bitmap data if that's not where you started).
See How to encode an image for a discussion on how to do this. The C# version of this documentation is still in progress, but you will use the same classes and methods as are described in the JavaScript document, except the functions are projected into C# in TitleCase instead of in camelCase.
--Rob
- Marked As Answer by Min ZhuMicrosoft Contingent Staff, Moderator Wednesday, March 21, 2012 2:51 AM
-
Thursday, March 29, 2012 8:57 PM
How can I create the IBuffer? I can do something like this:
byte[] res = new byte[fileSize]; IBuffer buffer = res.AsBuffer();
But how can I get the fileSize?
- Edited by Ahmed Aly 16 Thursday, March 29, 2012 9:19 PM


