This is the fourth post regarding Isolated Storage in Windows Phone app. In this post I am going to talk about How to read and save captured images in isolated storage.
Note: To understand this post better you should test the following code on a real phone not an emulator as camera of emulator will give you a black screen.
1. Before starting with this post you should have a better understanding of Photochoosertask and CameraCaptureTask.
If you don’t have any idea about these tasks you can refer to the following post.
2. In the following post first I will explain you how to save and read the image chosen from medial library into isolated storage. Then I will explain you how to save the image captured from camera into the isolated storage and how you can read that image from isolated storage.
Both the tasks have similar code for saving and reading the image except the code for launching the tasks.
3. First create a blank project Saveimages.
4. Add the following namespaces to the page MainPage.xaml.cs.
5. Now first we will launch the photochoosertask and will select a image from media library and will save it to isolated storage.
Save the existing image
First create a button to save the existing image and add the following code to click event handler of the button.
The Task completed event handler of the choosertask will save the image to the isolated storage having the file name existing.jpg. The code is given below.
Now you can read the image from isolated storage and display it in the imagecontrol given on the MainPage by clicking on the read selected image button. The following code is given below.
Save the captured image
The procedure for the CameraCapturetask is same as that of photochooser. We will create a button to launch the CameraCapturetask and will save the captured image in isolated storage having the name captured.jpg.
We can read the captured image in the same way as we did for the Photochooser task. The code for the read captured image button is as shown below.
Note: You will observe that the code for both the tasks will be similar as there is no difference between the read save image code of both the tasks except the filename.
6. I hope this post will be helpful to you. You can download the full project source file from the link given below.
Download Full Project file Saveimages.zip
Isolated Storage in Windows Phone app – Introduction
Isolated Storage in Windows phone app – Store data in IsolatedStorageSettings
Isolated Storage in Windows phone app – Reading and saving text files